Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ukma!xanth!lll-winken!claris!krazy From: krazy@claris.com (Jeff Erickson) Newsgroups: comp.lang.c Subject: Re: When is a cast not a cast? Message-ID: <9996@claris.com> Date: 2 May 89 12:37:01 GMT References: <2747@buengc.BU.EDU> Organization: Claris Corporation, Santa Clara CA Lines: 35 From article <2747@buengc.BU.EDU>, by bph@buengc.BU.EDU (Blair P. Houghton): > 1 main() > 2 { > 3 char *c; > 4 char *p; > 5 int i; > 6 ... > 7 c = "somestring"; /* Nothing fancy, null-terminated. */ > 8 i = 4; /* For example. */ > 9 ... > 10 p = (c + (char *) i); /* More trouble than it's worth... */ > 11 ... > 12 } > > 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... Well, first of all, the only arithmetic operations allowed on pointers are pointer+integer, integer+pointer, pointer-integer, and pointer-pointer. Pointer+pointer is illegal, and therefore, "operands of + have incompatible types". Secondly, I believe what you *want* on line 10 is p = c + i; This is equivalent to "p = &(c[i]);". It sets p equal to a pointer to the i'th char after c. -- Jeff Erickson Claris Corporation | Birdie, birdie, in the sky, 408/987-7309 Applelink: Erickson4 | Why'd you do that in my eye? krazy@claris.com ames!claris!krazy | I won't fret, and I won't cry. "I'm a heppy, heppy ket!" | I'm just glad that cows don't fly.