arrays and structures in C
Michael Meissner
meissner at xyzzy.UUCP
Wed Apr 27 04:57:42 AEST 1988
In article <143 at polygen.UUCP> pablo at polygen.uucp (Pablo Halpern) writes:
| (Every compiler I know of the address of a struct is the same as the address
| of its first element. dpANS requires this.)
| However, I don't understand your objection to:
|
| pointer = (rather_large_type *) malloc(some_large_integer *
| sizeof(rather_large_type));
|
| Which seems the same to me.
No, no, no, no. A pointer to a structure is not the same as the pointer
to it's first element because the types are different. If you convert
them to the same type, I would agree then that the pointers are the
same. On machines which have different representations for pointers
(say a pointer to a word and a pointer to a byte), if the first member
of the structure is a char or char array, the member's address would be
a byte pointer, whereas the structure's address would be a word pointer.
--
Michael Meissner, Data General. Uucp: ...!mcnc!rti!xyzzy!meissner
Arpa/Csnet: meissner at dg-rtp.DG.COM
More information about the Comp.lang.c
mailing list