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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:16:46+00:00 2026-05-15T17:16:46+00:00

I keep looking, but it seems like there’s zero interest from compiler developers in

  • 0

I keep looking, but it seems like there’s zero interest from compiler developers in supporting these.

To me, it seems odd – basically, current C++ has restrictions on unions that were always an irritation and never appropriate. You’d think that basically removing a few error checks would be a relatively simple way to tick an extra c++0x support box, but AFAICT no compiler developers have done so yet.

Why I’m interested is because it provides a simple solution to a recurring problem in data structure coding – how to reserve memory for an instance of some unknown (template parameter) type, preferably with as much type safety as possible in the circumstances, but without invoking any constructor that happens to be defined on that type. The really important point is that alignment rules must be followed.

An unrestricted union is perfect for this – it gives you a type which has no constructors or destructors, but which has the right size and alignment to allow any member. There are of course ways to explicitly construct and destruct when needed, and when you need typesafe access, you just use the appropriate union member to access it. Support for “proper” unions can be useful too, but you get huge benefits even for a single-member union such as…

union Memory_For_Item_t
{
  Item_t  m_Item;
};

Even with the standardized alignment handling features in C++0x, this approach wins for convenience and safety when e.g. you want space for x items in a node, not all of which will be in use (or constructed) at any time. Without C++0x, we are still in the dark ages WRT alignment issues – every compiler does it its own non-standard way.

The only problem with unrestricted unions – there’s no support for them that I can find.

  • 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-15T17:16:46+00:00Added an answer on May 15, 2026 at 5:16 pm

    Near future? I wouldn’t count on it. As http://wiki.apache.org/stdcxx/C%2B%2B0xCompilerSupport lays out well, none of the current compilers support it even though many over C++0x features are being implemented.

    However as N2544 explains:

    The current work-around to the union limitations is to create a fake union using template programming or casts.

    So, the situation you are describing probably already has a solution, although a bit messy.

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

Sidebar

Ask A Question

Stats

  • Questions 460k
  • Answers 460k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Your main error is very small and could be very… May 15, 2026 at 11:45 pm
  • Editorial Team
    Editorial Team added an answer The only explanation for this is the that items array… May 15, 2026 at 11:45 pm
  • Editorial Team
    Editorial Team added an answer Have you looked into Migrations? They allow you to alter… May 15, 2026 at 11:45 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.