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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:35:47+00:00 2026-05-14T15:35:47+00:00

I have a C# background. I am very much a newbie to a low-level

  • 0

I have a C# background. I am very much a newbie to a low-level language like C.

In C#, struct‘s memory is laid out by the compiler by default. The compiler can re-order data fields or pad additional bits between fields implicitly. So, I had to specify some special attribute to override this behavior for exact layout.

AFAIK, C does not reorder or align memory layout of a struct by default. However, I heard there’s a little exception that is very hard to find.

What is C’s memory layout behavior? What should be re-ordered/aligned and not?

  • 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-14T15:35:47+00:00Added an answer on May 14, 2026 at 3:35 pm

    In C, the compiler is allowed to dictate some alignment for every primitive type. Typically the alignment is the size of the type. But it’s entirely implementation-specific.

    Padding bytes are introduced so every object is properly aligned. Reordering is not allowed.

    Possibly every remotely modern compiler implements #pragma pack which allows control over padding and leaves it to the programmer to comply with the ABI. (It is strictly nonstandard, though.)

    From C99 §6.7.2.1:

    12 Each non-bit-field member of a
    structure or union object is aligned
    in an implementation- defined manner
    appropriate to its type.

    13 Within a
    structure object, the non-bit-field
    members and the units in which
    bit-fields reside have addresses that
    increase in the order in which they
    are declared. A pointer to a structure
    object, suitably converted, points to
    its initial member (or if that member
    is a bit-field, then to the unit in
    which it resides), and vice versa.
    There may be unnamed padding within a
    structure object, but not at its
    beginning.

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

Sidebar

Related Questions

I would like very much to create a web page which would have the
I don't have very much background regarding COM nor coclasses, so I don't quite
The new layout of YouTube added a background random-noise which I like very much,
I am very much an Android newbie and I have built a simple RSS
I have a strong database background but very little practical experience with ms sql
As background I have a very long ID that too long to display in
I have a website that requires a very large background image. The page loads
I'm an iPhone/Objective-C newbie with an extensive Java background. I'm learning more about memory
Background First of all, much gratitude to atebits for their very informative blog post
I am very much confused between instance variables and property. I have read number

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.