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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:57:30+00:00 2026-06-03T13:57:30+00:00

Is there a way with compiler flags to create the same memory layout of

  • 0

Is there a way with compiler flags to create the same memory layout of a base class and a derived class under msvc compared to its equivalent in gcc? Im using VS2010 and comparing it to GCC 4.1.1

So

#if define _MSVC
// window 
DALIGN(A,B) __declspec(align(A)) B
#else
// GCC
DALIGN(A,B) B __attribute__((aligned(A)))
#endif
class A
{ 
  DALIGN(CVector V,16);
  int a;
}
class B : public A
{
  int b;
}

A is 16byte aligned making it 0x20(32)
B is also 16 byte aligned, but is either also 0x20(32) on GCC but on msvc it is 0x30(48)

is there a way to force the msvc to pack the data like GCC is?

Reason for this: I create data and load it directly into the classes on different platforms. What would really be nice is if I could use the exact same data layout on both platforms. (Yes endian is the same on both platforms)

  • 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-03T13:57:32+00:00Added an answer on June 3, 2026 at 1:57 pm

    Adding #pragma pack(push, 4) / #pragma pack(pop)
    around the class A and class B succeeded in correctly aligning the data as GCC aligns it.

    Note that if the inheritance is extended, it seems like for any required aligned class and forward through the inheritance all require the packing.
    Example classes A,B,C,D,E,F
    C has aligned members
    C,D,E,F all require the packs around them.

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

Sidebar

Related Questions

Is there any way to suppress Compiler warnings ?? Thanks
Is there a way of forcing the C# compiler to ignore missing operator overloads
Is there a way to instruct c# compiler to output source at different stages
Is there a standard/common way to give compiler-style error messages that point to a
is there a way to add a compiler flag independently on what the build
Is there a way to create compile time errors if a certain method is
I'm looking for a way to create a class that has a default public
Is there some way to compile (with the CSC task) a WPF Application with
Is there a way to compile apple script code on the command line from
Is there any way to pre compile stored procedures in SQL Server? My requirement

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.