When is a cast not a cast?
Robert C. White Jr.
rwhite at nusdhub.UUCP
Thu May 4 08:02:10 AEST 1989
in article <2747 at buengc.BU.EDU>, bph at buengc.BU.EDU (Blair P. Houghton) says:
[p and c are of type (char *)]
> 10 p = (c + (char *) i); /* More trouble than it's worth... */
and totally inaccurate too boot. The + operator is defined separately for
the addition of a pointer-to-type and and interger. The specs indicate
that you will get the operation p=c+(i*sizeof_typeof_c) so the cast is
in error. pointer + interger is legal. if you had an array of structures
anmed "strarray" and you set a pointer to the Nth entry, and you wanted
to get to the N+Mth entry the following code is legal and correct:
structure somestruct strarry[1000], *ptr;
ptr = strarry[N];
...
ptr = ptr + M; /* or ptr += M */
...
[Unless, of course, I am brain dammaged and therefore not correct in
interpreting this stuff]
Rob.
More information about the Comp.lang.c
mailing list