[OT] Can global variable be passed into Python function?
davea at davea.name
Sun Mar 2 05:02:19 CET 2014
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 ï¿½188.8.131.52.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. It's not the compiler that casts
the malloc return value to the struct type.
C++ does implicitly convert the result, and the return value of
new already has the struct type. But the runtime stores at least
two kinds of overhead on occasion, the array size, and the
vtable. So the malloc address can not be assumed to match the
struct beginning. (Not even considering that one can override
operator new at two levels)
Glad python doesn't have any of this mess.
More information about the Python-list