Thread: Strange struct padding?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229

    Strange struct padding?

    I understand that the standard doesn't specify padding etc etc, but this is a "real world" question.

    I have a struct
    Code:
    struct S {
            long long int a;
            int b;
            int c;
            char d;
            char e;
    };
    and I expect its size to be 18 bytes, since no padding is needed (ints already aligned to 4-bytes boundaries, and chars don't matter).

    But gcc 4.2.3 on x86-64 Linux gives me a size of 24. How does that work?

    *edit* is it so that if I stack them up in an array, the long long member will be aligned to 8-bytes boundaries? */edit*
    Last edited by cyberfish; 12-14-2008 at 01:45 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 12-03-2008, 03:10 AM
  2. sequential file program
    By needhelpbad in forum C Programming
    Replies: 80
    Last Post: 06-08-2008, 01:04 PM
  3. Looking for constructive criticism
    By wd_kendrick in forum C Programming
    Replies: 16
    Last Post: 05-28-2008, 09:42 AM
  4. Search Engine - Binary Search Tree
    By Gecko2099 in forum C Programming
    Replies: 9
    Last Post: 04-17-2005, 02:56 PM
  5. Bi-Directional Linked Lists
    By Thantos in forum C Programming
    Replies: 6
    Last Post: 12-11-2003, 10:24 AM