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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:36:17+00:00 2026-06-14T21:36:17+00:00

Here is a snippet: #pragma pack(4) struct s1 { char a; long b; };

  • 0

Here is a snippet:

#pragma pack(4)
struct s1
{
    char a;
    long b;
};
#pragma pack()

#pragma pack(2)
struct s2
{
    char c;
    struct s1 st1;
};
#pragma pack()


#pragma pack(2)
struct s3
{
    char a;
    long b;
};
#pragma pack()

#pragma pack(4)
struct s4
{
    char c;
    struct s3 st3;
};
#pragma pack()

I though sizeof(s4) should be 10 or 12. But it turns out to be 8.
I am using Visual C++ 6.0. Could someone tell me why?

  • 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-14T21:36:18+00:00Added an answer on June 14, 2026 at 9:36 pm
    #pragma pack(2)
    struct s3
    {
        char a;
        long b;
    };
    #pragma pack()
    

    So the packing alignment of s3 is 2, and its size is 1 (alignment 1) + 1 (padding) + 4 (alignment 2) = 6.

    #pragma pack(4)
    struct s4
    {
        char c;
        struct s3 st3;
    };
    #pragma pack()
    

    The packing alignment of s4 is 4, and its size is 1 (alignment 1) + 1 (padding) + 6 (alignment 2) = 8.

    Note that #pragma pack doesn’t “extra-align” anything with looser alignment requirements. It only reduces alignment, i.e. controls “packing” alignment.

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

Sidebar

Related Questions

I found this code snippet here , but I just can't figure out what
So here's a snippet of my code: struct dv_nexthop_cost_pair { unsigned short nexthop; unsigned
I'm a socket programming newbie. Here's a snippet: struct sockaddr_storage client_addr; ... client_addr_size =
I found a code snippet here , which I wanted to use, but I
So there exists a snippet here : I was going tor reuse this, but
Here's a snippet of code I saw on the web and I'm wondering if
Here's a snippet from my application: class PortolioItem(models.Model): ... user = models.ForeignKey(User) contract =
Here's a snippet of a script of mine attempting to put extra Unicode awesomeness
Here is a snippet of the official Apple Documentation of AudioBufferList (Core Audio Data
Here is a snippet of my code $fp = fsockopen($s['url'], 80, $errno, $errstr, 5);

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.