pointer question
cobb at utcsstat.UUCP
cobb at utcsstat.UUCP
Mon Apr 9 15:50:41 AEST 1984
If anyone out there is still not convinced about "p = p + 4" portability,
after reading Archie's explanation (Archie Lachner), I submit the
following:
given a structure struct X {
int a;
int b;
int c;
}
with a register pointer p of type X;
p = p + 4 generates
addl $48,reg_n,reg_n ; add decimal 48 to register
; VAX - berkeley C compiler
and
add $30,reg_n ; add octal 30 (24) to register
; 11/70 - Bell C Compiler
As you might've guessed, reg_n is p.
In each case, the actual value added is <size of struct> * 4.
Thus, any fears about "p = p + n" is quite unfounded.
In fact, K&R states that a construct p[i] is actually
treated as p + i.
If this is still not convincing enough, c'est la vie !!
OZ
Ozan S. Yigit (utzoo!utcsstat!cobb)
(utzoo!yetti!ozan)
Dept. of Computer Science
York University
More information about the Comp.lang.c
mailing list