On 2014-02-24, Michael Torrie <torr...@gmail.com> wrote:
> On 02/24/2014 11:05 AM, j.e.ha...@gmail.com wrote:
>> typedef struct {
>>   int value;
>> } Number;
>> 
>>   Number *o;
>>   o = malloc(sizeof(*o));
>>   o->value=3;
>>   printf("o<%p>, o->value<%p>\n", o, &o->value);
>> 
>> o<0x9fe5008>, o->value<0x9fe5008>
>> 
>> Is the compiler borked?
>
> Why would you think that? The address of the start of your malloc'ed
> structure is the same as the address of the first element.  Surely
> this is logical?

Not only is it logical, the C standard explicitly requires it.  Here's
a second-hand citation since I don't happend to have an actual copy of
the standard on hand:

    C1x ยง6.7.2.1.13:

       A pointer to a structure object, suitably converted, points to
       its initial member ... and vice versa. There may be unnamed
       padding within a structure object, but not at its beginning.

-- 
Grant Edwards               grant.b.edwards        Yow! I'm gliding over a
                                  at               NUCLEAR WASTE DUMP near
                              gmail.com            ATLANTA, Georgia!!
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to