[Tutor] struct question
Marc Tompkins
marc.tompkins at gmail.com
Tue Feb 3 20:03:38 CET 2009
On Tue, Feb 3, 2009 at 10:29 AM, W W <srilyk at gmail.com> wrote:
>
>
> On Tue, Feb 3, 2009 at 6:25 PM, bob gailer <bgailer at gmail.com> wrote:
>
>> >>> struct.calcsize('s')
>> 1
>> >>> struct.calcsize('d')
>> 8
>> >>> struct.calcsize('sd')
>> 16
>>
>> Why? Should not that be 9?
>>
>
> >>> struct.calcsize('ds')
> 9
>
> at least on the current box I'm running. It also gave me this:
>
> >>> struct.calcsize('sd')
> 12
>
> so I must confess suspicion...
>
> HTH though,
> Wayne
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
More results to chew on:
>>> struct.calcsize('s')
1
>>> struct.calcsize('d')
8
>>> struct.calcsize('sd')
16
>>> struct.calcsize('ds')
9
>>> struct.calcsize('dss')
10
>>> struct.calcsize('dssssss')
14
>>> struct.calcsize('dsd')
24
I believe it's a matter of alignment:
> Native size and alignment are determined using the C compiler's sizeofexpression. This is always combined with native byte order.
>
> Standard size and alignment are as follows: no alignment is required for
> any type (so you have to use pad bytes); short is 2 bytes; int and longare 4 bytes;
> long long (__int64 on Windows) is 8 bytes; float and double are 32-bit and
> 64-bit IEEE floating point numbers, respectively. _Bool is 1 byte.
>
--
www.fsrtechnologies.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090203/b2277a19/attachment.htm>
More information about the Tutor
mailing list