Re: Struct Alignment

Discussion in 'C Programming' started by Jack Klein, Aug 4, 2003.

  1. Jack Klein

    Jack Klein Guest

    On Mon, 04 Aug 2003 01:50:19 +1000, Andre <>
    wrote in comp.lang.c:

    > Why does gcc (or any C compiler for that matter) align structs on double
    > word boundaries? And why should we align variables inside structs? One
    > clear advantage could be cache utilization but isn't that possible even
    > without alignment? Thanks
    >
    > -Andre


    There are some architectures that gcc compiles for (ARM for sure) that
    actually require specific alignment for specific data types.
    Accessing data at a misaligned address can generate a trap that kills
    the program.

    There are other architectures that actually just ignore one or more
    low bits when accessing certain types, acting as if they were 0 even
    if they are not.

    As to why gcc decides on any particular alignment for any particular
    hardware platform, ask in a gcc group. It is not a language issue.

    --
    Jack Klein
    Home: http://JK-Technology.Com
    FAQs for
    comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
    comp.lang.c++ http://www.parashift.com/c -faq-lite/
    alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c /faq
    Jack Klein, Aug 4, 2003
    #1
    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. Bryan Parkoff
    Replies:
    0
    Views:
    419
    Bryan Parkoff
    Apr 2, 2005
  2. Eric G.

    Re: Struct Alignment

    Eric G., Aug 3, 2003, in forum: C Programming
    Replies:
    2
    Views:
    343
    Richard Heathfield
    Aug 4, 2003
  3. Chris Fogelklou
    Replies:
    36
    Views:
    1,356
    Chris Fogelklou
    Apr 20, 2004
  4. S.Tobias

    struct and union alignment

    S.Tobias, Sep 23, 2004, in forum: C Programming
    Replies:
    67
    Views:
    1,346
    Dave Thompson
    Oct 4, 2004
  5. struct alignment

    , May 5, 2005, in forum: C Programming
    Replies:
    2
    Views:
    311
    Tim Prince
    May 5, 2005
Loading...

Share This Page