Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!rutgers!bellcore!faline!thumper!ulysses!andante!alice!ark From: ark@alice.UUCP (Andrew Koenig) Newsgroups: comp.lang.c Subject: Re: When is a cast not a cast? Message-ID: <9282@alice.UUCP> Date: 2 May 89 16:36:29 GMT References: <2747@buengc.BU.EDU> Organization: AT&T Bell Laboratories, Liberty Corner NJ Lines: 28 In article <2747@buengc.BU.EDU>, bph@buengc.BU.EDU (Blair P. Houghton) writes: > 3 char *c; > 4 char *p; > 5 int i; > 6 ... > 7 c = "somestring"; /* Nothing fancy, null-terminated. */ > 8 i = 4; /* For example. */ > 10 p = (c + (char *) i); /* More trouble than it's worth... */ > wherupon both the lint(1) and cc(1) in my Ultrix 2.2 piped-up with > warnings that the 'operands of + have incompatible types' on line 10... Correct. You cannot add two pointers -- you can only add a pointer and an integer. You can SUBTRACT two pointers (to the same type); the result of that is an integer, not a pointer. If p is a pointer to element n of some array, then p+i is a pointer to element n+i of that array. If p isn't a pointer to an array element, you're on your own. [C-T&P, p. 29] -- --Andrew Koenig ark@europa.att.com