p[1] vs. *(p+1)

Chip Salzenberg chip at tct.uucp
Tue Aug 28 03:05:56 AEST 1990


According to cbp at icc.com (Chris Preston):
>  For instance, I am told that the following is a problem in Kanji
>
>  char p[10]; /* xscc provides for allowing twenty bytes as needed in Kanji */
>
>  *(p+1)='x'; /* this is the next byte, and an error */ 
>   p[n+1]='x'; /* this is the next _character_ and ok */

Just so no one panics: Unless I misunderstand Chris Preston's example,
this bit of code is not a harbinger of things to come, but rather an
artifact of a broken compiler.

Any compiler that considers "*(p+1)" and "p[1]" to be different does
not comply with the ANSI standard -- or with K&R, for that matter.
Since time immemorial, "*(a+b)" and "a[b]" have been synonymous, and
such is C today.
-- 
Chip Salzenberg at Teltronics/TCT     <chip at tct.uucp>, <uunet!pdn!tct!chip>



More information about the Comp.lang.c mailing list