[OT] Can global variable be passed into Python function?
Grant Edwards
invalid at invalid.invalid
Mon Feb 24 14:42:22 EST 2014
On 2014-02-24, Michael Torrie <torriem at gmail.com> wrote:
> On 02/24/2014 11:05 AM, j.e.haque at 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!!
More information about the Python-list
mailing list