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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:31:38+00:00 2026-06-18T07:31:38+00:00

I use a datastructure in my project and in the context of a paricular

  • 0

I use a datastructure in my project and in the context of a paricular structure i have a doubt about strucure padding. First Look at the strucure given below. I use Visual Studio 2008 compiler.

typedef struct tagDATA_PACK
{
   DWORD dDataLength;
   BYTE bFlags;
   BYTE bAttrib;
   BYTE bOffset;
}DATA_PACK;

Question1: How much is the size of the above structure?
it shows 8 bytes. it is correct. But,

consider the modified structure given below?

typedef struct tagDATA_PACK
{
   DWORD dDataLength;
   BYTE bFlags;
}DATA_PACK;

here the size is same as the above 8byte structure.
My doubt here is, where would be the compiler adding the extra 3bytes?
is it after BYTE bFlags or before it?

All your answer is greatly appreciated.

  • 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-06-18T07:31:40+00:00Added an answer on June 18, 2026 at 7:31 am

    Alignment and padding for structs and classes is not specified by the standard. It’s entirely down to the compiler. However, all sane compilers follow the underlying platform ABI. In your case the platform is Windows, and the Windows platform ABI is adhered to.

    The padding in this case, for both structs, is after the last member. The first struct has one extra padding byte, and the second struct has three extra padding bytes.

    The largest type in the struct has size 4. And that means that the overall size will be a multiple of 4. For both structs, the smallest multiple of 4 that accommodates the struct is 8.

    Each data type has an alignment property. A 4 byte data type has alignment of 4. A 2 byte data type has an alignment of 2. A type with alignment of 4 is aligned when placed on a 4 byte offset from the start of the struct. A type with alignment of 2 is aligned when placed on a 2 byte offset from the start of the struct. And so on.

    Members are placed at the smallest offset that respects both the order of declaration of members, and the alignment property of the members.

    For an example with padding internal to the struct consider this struct

    struct MyStruct
    {
       char c;
       int i;
    };
    

    The alignment of c is 1, and the alignment of i is 4. So, c is placed on a 1 byte boundary, and i must be placed on a 4 byte boundary. That means that c will have offset 0, then there will be 3 padding bytes, and then i will be laid out at an offset of 4.

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

Sidebar

Related Questions

i have some functions(charfreq,wordfreq,charcount,wordcount,parerror) and i want to use it in dataStructure with the
Which datastructure would you use in the place of X to have efficient merges,
I have the need to use a Stack-like data structure for a program that
I use Devise in my new project,but I have some problems in roles. There
In my project I have a small data structure Key . public class Key
i have a project in c++03 that have a problem with data structure: i
A data structure that I use commonly in multi-threaded applications is a ConcurrentHashMap where
I want to use pprint's output to show a complex data structure, but I
Is there a .NET data structure I could use for bidirectional lookup? Here's the
I wonder what is the best C# data structure I should use to sort

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.