Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6469023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T05:56:42+00:00 2026-05-25T05:56:42+00:00

I always assume, as they said here http://en.wikipedia.org/wiki/Data_structure_alignment , It is important to note

  • 0

I always assume, as they said here http://en.wikipedia.org/wiki/Data_structure_alignment, “It is important to note that the last member is padded with the number of bytes required so that the total size of the structure should be a multiple of the largest alignment of any structure member”

So for the struct like this, its size should be 16 at a 32 processor

typedef struct
{
   double   s;  /* 8 bytes */
   char     c;  /* 7 bytes padding at the end of make the total size 8*2 */
} structa_t;  

So I was quite surprised to the size is 12 instead of 16!! Why is that ? Can someone cast some light on it ?

sizeof(double) = 8
sizeof(structa_t) = 12

BTW, so system info

$ uname -a
Linux 2.6.18-8.el5xen #1 SMP Thu Mar 15 21:02:53 EDT 2007 i686 i686 i386 GNU/Linux
$ gcc --version
gcc (GCC) 4.1.1 20070105 (Red Hat 4.1.1-52)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T05:56:43+00:00Added an answer on May 25, 2026 at 5:56 am

    The key wording here is:

    …the total size of the structure should be a multiple of the largest alignment of any structure member…

    On your system, the aligment of a double is 4, not 8.

    If you wait for C1x, you can use the _Alignof operator (similar to sizeof). On your system,

    sizeof(double) == 8
    _Alignof(double) == 4
    

    You can test the alignment in a more primitive way in C89,

    #include <stdlib.h>
    struct char_double { char x; double y; };
    #define DOUBLE_ALIGNMENT offsetof(struct char_double, y)
    

    Or with a macro,

    #define alignof(x) offsetof(struct { char a; x b; }, b)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it safe to assume that NULL always translates to false in C? void
Is it safe to assume that $_SERVER['REMOTE_ADDR'] always returns a IPv4 address ? Thanks!
Is it safe to assume that java.util.concurrent.CompletionService.take().isDone() will always return true? If so, why
std::map<int,int> mapy; ++mapy[5]; Is it safe to assume that mapy[5] will always be 1?
On iOS I have always assume that it is not possible to do OpenGL
Let's say I have a database column that should always be in uppercase. Here
I know that modern CPUs can execute out of order, However they always retire
Or are they only manipulated by the server? For instance, can we always assume
I've always assumed that before I can use the Dvorak layout I need to
For some reason I have always assumed that most of the time a variable

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.