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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:36:46+00:00 2026-05-26T07:36:46+00:00

The C++ standard (quoting from draft n3242) says the following about subobjects [intro.object]: Unless

  • 0

The C++ standard (quoting from draft n3242) says the following about subobjects [intro.object]:

Unless an object is a bit-field or a base class subobject of zero
size, the address of that object is the address of the first byte it
occupies. Two distinct objects that are neither bit-fields nor base
class subobjects of zero size shall have distinct addresses.

Now, given the following snippet:

struct empty { };
struct member: empty { };
struct derived: empty { member m; };

int main(void)
{
    printf("%d", sizeof(derived));
    return 0;
}

gcc I believe prints out 2, and Visual C++ 2010 prints out 1. I suspect gcc is taking the standard to mean you can’t alias the storage of types if they represent different objects. And I bet MSVC is taking the standard to mean if one subobject is zero sized, you can do whatever you want.

Is this unspecified behavior?

  • 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-05-26T07:36:47+00:00Added an answer on May 26, 2026 at 7:36 am

    Expanding on my earlier comment:

    An object is identified by its address. If you compare the addresses (like pointers) of two objects of the same type and they compare equal, the pointers are considerd to point to the same object.

    Objects of different types cannot be compared directly this way, so they are allowed to have the same address. One example is a struct and its first member. They cannot be of the same type. Neither can a base class and a derived class, so they could possibly have the same address if the base class is empty.

    However, a base class and the first member of the derived class can be of the same type. This is not a problem unless the base class is also empty and the compiler tries the empty base class optimization. In that case we could have pointers to two different objects of the same type compare equal, and therefore believe that they were the same object.

    So, if the members have different types (empty and char) they can have the same address. If they are of the same type they cannot, because that would break tests for object identity like if (this != &that), sometimes used to test for things like self assignment.

    By the way, Microsoft agrees that this is a bug in their compiler but have other, more urgent, things to fix first.

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

Sidebar

Related Questions

The standard says A variable is introduced by the declaration of an object. The
quoting from The C++ Standard Library by N M Jousttis, Section 5.9 #include <
Standard Entry Sequence : _function: push ebp ;store the old base pointer mov ebp,
In standard ASP.net applications ASP.net offered some protection from XSS attacks with validateRequest throwing
In standard SQL, is there a way to say: select mubmle as x from
The standard provides a template specialization of std::unique_ptr which correctly calls the delete[] from
The standard C library functions strtof and strtod have the following signatures: float strtof(const
The standard way of intersecting two sets in C++ is to do the following:
C++ Standard 8.3.2/4 says: There shall be no references to references, no arrays of
In standard C# synchronization classes (like Monitor), if several threads wait on some object

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.