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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:59:39+00:00 2026-05-27T18:59:39+00:00

C11 supports anonymous structures, like so: struct Foo { struct { size_t x, y;

  • 0

C11 supports anonymous structures, like so:

struct Foo
{
    struct
    {
        size_t x, y;
    };
};
struct Foo f;
f.x = 17;
f.y = 42;

Basically, the members of such a struct are treated as if they were members of the enclosing struct or union (recursively, if the enclosing structure was itself anonymous).

What was the rationale for C++11 not also including anonymous structures? They’re only uncommonly useful (mostly inside unions, to eliminate the typing of an identifier for the struct), certainly. But they seem an obvious enough addition to the specification (and one already implemented by many compilers) that surely they must have been discussed, at the very least to preserve compatibility with the C11 standard. So why weren’t they added?

  • 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-27T18:59:39+00:00Added an answer on May 27, 2026 at 6:59 pm

    Little effort has been made to maintain compatibility between C++ and C as the two languages evolve. Notice that variable length stack arrays have been in C since 1999, but weren’t included in C++11. While they generally don’t introduce things that contradict one another, the C++ committee isn’t exactly bending over backwards to make sure that C++11 is compatible with versions of C beyond C89.

    Furthermore, this feature would be quite complex in C++, because a struct is nothing more than a class. And an anonymous struct/class should have all of the features of a regular struct/class, yes? Otherwise, what’s the point of having it?

    What would it mean to construct a nameless struct? How would you define the constructor? Something as simple as:

    struct Foo
    {
        struct
        {
            size_t &x;
        };
    };
    

    is simply not possible because the inner struct has no constructor. And there’s no way to specify one. A struct cannot construct the members of another struct within it.

    For something like this:

    struct Foo
    {
        size_t outer;
        struct
        {
            void SomeFunc();
            size_t x;
        };
    };
    

    What this pointer does SomeFunc get? What would the type of this be, the nameless and unnamed type? How would you even define SomeFunc outside of the struct? The name of SomeFunc can’t be Foo::SomeFunc, because SomeFunc lives in an inner scope.

    It’s just too complex for C++ to deal with. And certainly not worthwhile enough to bother with adding that complexity for.

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

Sidebar

Related Questions

Anonymous structs have been added in the C11 standard, so typedef struct { struct
C11 adds, among other things, 'Anonymous Structs and Unions'. I poked around but could
I know the C11 standard is only a month old, but the drafts for
I have this CSS code: <style> body { position:absolute; background-image: url(art/c11.jpg); width:100%; height:100%; }
i have a list like this: G05 G03 F02 F06 G10 A03 A11 E10
I can see practical use for a const volatile qualified variable, like const volatile
C++03 allows to create template class which inheritances from template parameters: // c++03 struct
I have a big dataframe, but small example would be like this: mydf <-
I just read an article on the C++0x standard: http://www.softwarequalityconnection.com/2011/06/the-biggest-changes-in-c11-and-why-you-should-care/ It said nullptr was
I have such xml: <A1> <B1> <C1> <C2> <C3> </B1> <B2> <C4> <C5> <C6>

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.