When is a cast not a cast?
Andrew Koenig
ark at alice.UUCP
Wed May 3 02:36:29 AEST 1989
In article <2747 at buengc.BU.EDU>, bph at 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 at europa.att.com
More information about the Comp.lang.c
mailing list