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. Advertisements

  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. Advertisements

  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. Advertisements

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:
    599
    RA Scheltema
    Jan 6, 2004
  2. Gunnar G

    struct in struct

    Gunnar G, May 31, 2004, in forum: C++
    Replies:
    14
    Views:
    1,037
  3. DanielEKFA
    Replies:
    8
    Views:
    842
    DanielEKFA
    May 16, 2005
  4. James Harris
    Replies:
    4
    Views:
    1,773
    James Harris
    Oct 9, 2003
  5. Chris Fogelklou
    Replies:
    36
    Views:
    1,828
    Chris Fogelklou
    Apr 20, 2004
  6. Chandu

    struct.calcsize problem

    Chandu, Nov 7, 2005, in forum: Python
    Replies:
    3
    Views:
    850
    Chandu
    Nov 9, 2005
  7. Fernan Bolando

    Pointer to struct or Struct parameters

    Fernan Bolando, Aug 7, 2004, in forum: C Programming
    Replies:
    6
    Views:
    551
    Fernan Bolando
    Aug 8, 2004
  8. Glen Rice

    struct calcsize discrepency?

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