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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T19:58:34+00:00 2026-05-12T19:58:34+00:00

I want to have a base class which dictates the alignment of the objects

  • 0

I want to have a base class which dictates the alignment of the objects which inherit from it. This works fine for the heap because I can control how that gets allocated, and how arrays of it get allocated in a custom array template. However, the actual size of the class as far as C++ is concerned doesn’t change at all. Which is to say if I perform pointer arithmetic on a pointer of the derived class then it will skip to the wrong location. That’s issue one.

Issue two is stack alignment. There doesn’t seem to be a way to directly force the entire stack to be 16 byte aligned pointers.

The only thing I can see to affect these at all is the vc++ and g++ compiler specific settings, but the problem here is I don’t want to have to manually fix the alignment all the time. That would be bound to be error prone, not to mention a pain.

I could also maybe make some kind of smart pointer but that would introduce more issues, too.

If I just align the base class, will the child classes be aligned, as well? If so, that would solve most of my problems but that seems doubtful to be the case (though I will try this).

  • 1 1 Answer
  • 1 View
  • 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-12T19:58:34+00:00Added an answer on May 12, 2026 at 7:58 pm

    If a base class has a particular alignment requirement, then any derived classes will have at least that alignment (they could get a stricter alignment requirement due to their own members). Otherwise the compiler couldn’t guarantee that accessing the base members would meet the requirements they have.

    However, there’s really nothing you can portably do for stack alignment – that’s handled entirely by the compiler and the compiler’s platform ABI requirements. As you indicate, a compiler option or maybe a pragma might let you exert some control, but nothing portable.

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

Sidebar

Related Questions

My problem is this, I have a base class from which classes are derived.
I have an abstract base class from which many classes are derived. I want
I have a base class which contains an abstract/MustInherit method. I want this method
I have a common base class from which all my ASMX webservice classes will
I want to get your opinion on this. I have a class which is
So I have a base class Animal which has 2 classes inheriting from it,
I have a base class which looks something like this: class Base { public:
This is a rather simple question, I have a base class which implements common
I have a base class Character which has several classes deriving from it. The
I want to have a little class which manages raw memory with this API

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.