[OT] Can global variable be passed into Python function?

Grant Edwards invalid at invalid.invalid
Sun Mar 2 17:45:28 CET 2014


On 2014-03-02, Dave Angel <davea at davea.name> wrote:
>  Grant Edwards <invalid at invalid.invalid> Wrote in message:
>> On 2014-02-24, Michael Torrie <torriem at gmail.com> wrote:
>>
>>>
>>> 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.
>
> The quote you make from the C standard doesn't mention malloc,  so
> you're arguing different things.

No, I'm not.  A pointer to a structure object and a pointer to it's
first field are the same.  It doesn't matter where the object came
from.

> It's not the compiler that casts the malloc return value to the
> struct type.

That's irrelevent.  The actual location of the memory containing the
struct object (static, stack, heap, shared) doesn't matter.  The
address of the first field in a struture object _is_ the address of
the structure object.

-- 
Grant



More information about the Python-list mailing list