Bug in struct.calcsize() ?

Discussion in 'Python' started by James Lamanna, Apr 9, 2004.

  1. Noticed this under 2.3.3:

    struct.calcsize('H') => 2
    struct.calcsize('BBB') => 3
    struct.calcsize('BBBH') => 6

    Umm, shouldn't 'BBBH' return 5?

    Please CC me for I am not subscribed.

    --
    James Lamanna
    James Lamanna, Apr 9, 2004
    #1
    1. Advertising

  2. James Lamanna wrote:

    > Noticed this under 2.3.3:
    >
    > struct.calcsize('H') => 2
    > struct.calcsize('BBB') => 3
    > struct.calcsize('BBBH') => 6
    >
    > Umm, shouldn't 'BBBH' return 5?
    >
    > Please CC me for I am not subscribed.
    >

    I'll also post here (for the benefit of others that might google for this
    question).

    In the struct documentation, there is a table for byte order and alignment.
    Providing one of the characters '@=><!' as the first character of your
    string specifies the byte order and alignment behavior. Since your string
    doesn't specify one, then native byte order and alignment are assumed. In
    this case, your C compiler aligns 16-bit ints to a 16-bit boundary. To
    pack without padding, use '=' as the first character.

    struct.calcsize('=BBBH') => 5

    --
    Andy
    Andrew Henshaw, Apr 9, 2004
    #2
    1. Advertising

  3. Andrew Henshaw wrote:

    ....snip...

    I see you followed up to yourself with the solution! Now I just need to fix
    the bug in my newsreader (knode) that allows these followups to be
    scattered about the list, even though threading is turned on and sorting by
    subject is specified!

    --
    Andy
    Andrew Henshaw, Apr 9, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. RA Scheltema
    Replies:
    3
    Views:
    381
    RA Scheltema
    Jan 6, 2004
  2. Gunnar G

    struct in struct

    Gunnar G, May 31, 2004, in forum: C++
    Replies:
    14
    Views:
    788
  3. Chris Fogelklou
    Replies:
    36
    Views:
    1,357
    Chris Fogelklou
    Apr 20, 2004
  4. Chandu

    struct.calcsize problem

    Chandu, Nov 7, 2005, in forum: Python
    Replies:
    3
    Views:
    668
    Chandu
    Nov 9, 2005
  5. Glen Rice

    struct calcsize discrepency?

    Glen Rice, Dec 4, 2011, in forum: Python
    Replies:
    9
    Views:
    239
    Nobody
    Dec 6, 2011
Loading...

Share This Page