Grant Edwards <invalid@invalid.invalid> Wrote in message: > On 2014-02-24, Michael Torrie <torr...@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. 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. -- DaveA
-- https://mail.python.org/mailman/listinfo/python-list