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 6472305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:19:41+00:00 2026-05-25T06:19:41+00:00

Possible Duplicate: Size of struct with a single element Given any type A and

  • 0

Possible Duplicate:
Size of struct with a single element

Given any type A and the following struct:

struct S
{
    A a;
};

Are there any cases where sizeof(S) is greater than sizeof(A)?

For example, can sizeof(std::array<T, n>) be greater than sizeof(T[n])?

  • 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-25T06:19:41+00:00Added an answer on May 25, 2026 at 6:19 am

    While the struct can be padded, on all systems I know, the compiler will pad so that the alignment of the structure is the same as the largest alignment of its members. It does this so that an array of the structure will always be correctly aligned.

    So:

    struct S 
    {
       char a;
    } // Size 1, no padding
    
    struct S2 
    {
       unsigned int a;
       char b;
    } // Size 8, 3 bytes padding (assuming 32 bit integer)
    

    Edit: Note, that compilers can also add internal padding, to keep the alignment of the data correct.

    The C/C++ standard doesn’t specify any of these detail. What you want is the C ABI (application binary interface) for the system you’re running on, which should specify default layout for structs (compilers can choose to override this if they see fit, see also #pragma pack). For an example, look at the X86_64 ABI page 13, which states:

    Aggregates and Unions Structures and unions assume the alignment of
    their most strictly aligned compo- nent. Each member is assigned to
    the lowest available offset with the appropriate alignment. The size
    of any object is always a multiple of the object‘s alignment. An array
    uses the same alignment as its elements, except that a local or global
    array variable of length at least 16 bytes or a C99 variable-length
    array variable always has alignment of at least 16 bytes. Structure
    and union objects can require padding to meet size and alignment
    constraints. The contents of any padding is undefined.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Why isn’t sizeof for a struct equal to the sum of sizeof
Possible Duplicate: Sizeof an array in the C programming language? Why is the size
Possible Duplicate: Why isn’t sizeof for a struct equal to the sum of sizeof
Possible Duplicate: Are there any O(1/n) algorithms? Any algorithm whose complexity decreases with increase
Possible Duplicate: How do I find the size of a struct? Struct varies in
Possible Duplicate: Why isn't sizeof for a struct equal to the sum of sizeof
Possible Duplicate: Splitting a string into chunks of a certain size Is there anyway
Possible Duplicate: struct sizeof result not expected I have this C++ struct: struct bmp_header
Possible Duplicate: Maximum size for a SQL Server Query? IN clause? Is there a
Possible Duplicate: Why isn't sizeof for a struct equal to the sum of sizeof

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.