Can global variable be passed into Python function?
Chris Angelico
rosuav at gmail.com
Mon Feb 24 13:25:25 EST 2014
On Tue, Feb 25, 2014 at 5:20 AM, <random832 at fastmail.us> wrote:
> On Mon, Feb 24, 2014, at 13:05, 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?
>
> That's cheating. Try printf("o<%p>", &o);
It's not cheating, but it's showing something different. Comparing o
and &o->value shows that the structure itself and its first member are
at the same location in memory. Comparing o and &o shows that the
structure and the pointer to the structure are at different locations
in memory.
ChrisA
More information about the Python-list
mailing list