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

The Archive Base Latest Questions

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

Is there a way to detect at compile-time if a class has a vtable

  • 0

Is there a way to detect at compile-time if a class has a vtable or not? I am trying to ensure
a class is aligned to 64-byte boundaries and is 64 bytes in length. Adding a vtable increases
the class size to 128 bytes.

class __attribute__((aligned(64))) C
{
private:
    int64_t iValue;
    char iPadding[64 - sizeof(int64_t)];
};

This is fine. However

class __attribute__((aligned(64))) C
{
public:
    virtual ~C() {}

private:
    int64_t iValue;
    char iPadding[64 - sizeof(int64_t)];
};

screws things up.

Answer: aligned also pads, not just controls location. __declspec(align()) seems to do the same!

Edit: Still bamboozled. After putting a check in the constructor of C that checks that this is divisible by 64 and throw an exception if it’s not, I’m getting exceptions. Initially I though it might have to do with having instances of C on the stack, but after changing them to being heap-based the alignment check is still failing. I’ll just fall back to a factory function that calls posix_memalign and do in-place new (which is probably what std::aligned_storage eventually does)

  • 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-18T09:38:20+00:00Added an answer on June 18, 2026 at 9:38 am

    Instead of adding padding bytes manually, why not just use __attribute__((aligned(64))) and let the compiler align it for you whether or not there’s a vtable present? Then you’ll always get 64 byte alignment with no other work needed, and it removes the dependency on knowing the size of the vtable.

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

Sidebar

Related Questions

Is there a compile-time way to detect / prevent duplicate values within a C/C++
Is there a way or a tool that can, at compile time, detect if
Is there a way to detect when a UITextView has finished scrolling? As a
Is there any way in Java to get the compile time type of a
Is there a common way to detect if a symbol exists or not? Like
Are there any C++ compile time macros which exists to detect which Windows OS
Is there any way to detect if a commercial is playing? I'm using player.observe(models.EVENT.CHANGE,
Is there a way to detect page breaks with php? I generate a report
is there a way to detect if a header of a section in an
Is there a way to detect whether sys.stdout is attached to a console terminal

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.