Find the answer to your Linux question:
Results 1 to 3 of 3
Hopefully this is an easy question. in linux 64 bit I am creating a union that contains 2 structures 16 bytes each I want to use this union to create ...
  1. #1
    Just Joined!
    Join Date
    May 2009
    Posts
    7

    C structure allignment in 64 bit Linux

    Hopefully this is an easy question. in linux 64 bit I am creating a union that contains 2 structures 16 bytes each I want to use this union to create a list in which each element of the list will occupy exactly 16 bytes, since the size of the structures are 64 bit alligned I should not have to worry about the structures being padded with extra bytes correct?

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,974
    That would be correct. 16 bytes == 128 bits, or two 64-bit words. Assuming that the compiler will word-align structures, then these are naturally aligned. No filling is required.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  3. #3
    Linux Newbie theNbomr's Avatar
    Join Date
    May 2007
    Location
    BC Canada
    Posts
    150
    There are two aspects to your question, and the two are related: the alignment of the structure in memory (i.e. the starting address), and the alignment of the individual elements within the structure.
    The first aspect is up to the compiler, and as Rubberman points out, the compiler will tend to choose word or double-word alignment. The arrangement of elements within the structure can be influenced with the #pragma pack directive to force the style of packing that you want. Also, you may find the offsetof() macro useful for finding at runtime how the structure is aligned.
    --- rod.
    Stuff happens. Then stays happened.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...