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

Chris Angelico rosuav at gmail.com
Sun Mar 2 05:17:21 CET 2014


On Sun, Mar 2, 2014 at 3:02 PM, Dave Angel <davea at davea.name> wrote:
> 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

Whatever pointer malloc returns is the beginning of the *usable*
space. Any overhead for array size etc has to be before that; a
virtual function table pointer would be inside that space, but that's
very much compiler-dependent.

ChrisA



More information about the Python-list mailing list