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 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

I'm trying to make Core Data objects inherit from my own custom class rather
I have a bunch of repository classes which I want to unit-test using Visual
How to implement casting to a private base class in C++? I don't want
I'm experiencing a challenging problem, which has not been solvable - hopefully until now.
#include<iostream> using namespace std; class Abs { public: virtual void hi()=0; }; class B:public
In C++ for Windows, I have some object factory that is supposed to create
I've been slowly teaching myself the fundamentals of interface driven programming and I'm struggling
I'm writing a windows application in C++ and encountered the following problem when working
How would I tell the WCF service what KnownTypes to use when passing data
Is there a (practical) way to by-pass the normal (virtual) constructor calling order? Example:

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.