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

  • Home
  • SEARCH
  • 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 6648745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:41:29+00:00 2026-05-26T00:41:29+00:00

Is there any convention over the algorithm used to make the layouts of structs

  • 0

Is there any convention over the algorithm used to make the layouts of structs on C?

I want to be able to have a code running in a vm to be able to have structures compatible with their C counterparts, just like C# interop works. For this I will need to know how the alignment algorithm works. I gather there must be a convetion for that, as it works nicely on C#. I have in mind the probable algorithm they have used to work this out, but I haven’t found any proof it is the right one.

Here’s how I think it works:

for each declared field (by order of declaration)

  • See if the field fits in the remaining bytes (until next alignment)
  • If it doesn’t fit, align this field; otherwise add it to current offset

for example, on a 32-bit system for a struct like:

{
byte b1;
byte b2;
int32 i1;
byte b3;
}

would be like this with this algorithm:

{
byte b1;
byte b2;
byte[2] align1;
int32 i1;
byte b3;
byte[3] align2;
}
  • 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-26T00:41:29+00:00Added an answer on May 26, 2026 at 12:41 am

    In general, structure alignment in C depends on the compiler used, and especially the compiler options in effect at the time the structure declaration is processed. You can’t make any general assumptions except to say that for a particular structure in a particular program compiled with particular settings, the structure layout can be determined.

    That said, your guess closely matches what most compilers are likely to do with default alignment settings.

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

Sidebar

Related Questions

I have a doubt: - Is there any standard/convention that when should I use
Is there any official/unofficial/informal convention for alt+key namings ? maybe, Microsoft have some internal
I have many js files, with some naming convention. If there any tool that
Is there any way to create a naming convention for my primary key constraints
Is there a Java convention to refer to methods, static and otherwise, any specific
Are there any standalone type conversion libraries? I have a data storage system that
I need a query to make a Select over table1 and table2. I want
Is there some sort of convention-over-configuration on Entity Framework regarding the rowversion column? So
Are there any industry standard conventions for naming jar files?
is there any different in Connection string between SQL server Authentication and Windows Authentication

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.