Feature request for "friendship" of pointers in "C"
Holger Lamm
holger@e-gitt.net
Tue Mar 17 22:43:06 GMT 2020
Am 17.03.20 um 22:41 schrieb Andreas Schwab:
> On Mär 17 2020, Holger Lamm wrote:
>
>> No. The order of elements of structures in memory is implementation
>> defined and not guaranteed to be the order of enumeration in the
>> definition.
>
> That is not true. The first member is guaranteed to have the same
> address as the whole structure, and subsequent members have increasing
> addresses, in declaration order.
Sorry, I must confess.
ANSI C 6.5.8 (5) confirms that "... pointers to structure members
declared later compare greater than pointers to members
declared earlier in the structure"; I found no definition of address
to structure vs. address of structure member but there would be no
reason to have padding *before* the first element.
However, I see no reason for the original request to treat both pointers
as compatible. (I guess the request goes into the direction of not
issuing a type warning).
Pointer address might be the same, and the resulting code be working.
But the referenced objects are of different type, size and not compatible.
Regards,
Holger
More information about the Gcc
mailing list