[NTLUG:Discuss] OT C question
steve
sjbaker1 at airmail.net
Sat Feb 18 13:33:47 CST 2006
Spicerun wrote:
> Well, I'd love to know when that was added to the Ansi C standard
> then.... True, I haven't read the latest standard in detail, but this
> certainly wasn't the case in the past.
You're mistaken. In fact, this even pre-dates the ANSI C standard.
I have a copy of K&R's classic C book from the very first printing.
It clearly says that if you have:
int x [ 10 ] ;
...then x [ 5 ] is equivelent to *(x + 5).
That works even if 'x' is an array of structures or some other
strangely sized thing.
I know this is suprising - but the compiler really does multiply the '5'
by sizeof(int) before adding it onto x.
However, failure to adequately bracket these kinds of expressions is
such a horribly common error that I'd strongly advise people to continue
to use the [] syntax 'as nature intended'.
More information about the Discuss
mailing list