osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Can global variable be passed into Python function?


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