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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:00:40+00:00 2026-06-10T11:00:40+00:00

In C11 standard there is following definition of common initial sequence shared by structures

  • 0

In C11 standard there is following definition of common initial sequence shared by structures nested within a single union:

6.5.2.3/6

One special guarantee is made in order to simplify the use of unions:
if a union contains several structures that share a common initial
sequence (see below), and if the union object currently contains one
of these structures, it is permitted to inspect the common initial
part of any of them anywhere that a declaration of the completed type
of the union is visible. Two structures share a common initial
sequence
if corresponding members have compatible types (and, for
bit-fields, the same widths) for a sequence of one or more initial
members.

EXAMPLE 3 The following is a valid fragment:

union {
    struct {
        int alltypes;
    } n;

    struct {
        int type;
        int intnode;
    } ni;

    struct {
        int type;
        double doublenode;
    } nf;
} u;

u.nf.type = 1;
u.nf.doublenode = 3.14;
/* ... */
if (u.n.alltypes == 1)
        if (sin(u.nf.doublenode) == 0.0)
            /* ... */

According to my understanding of this article, the above code, however, is invalid.

In the outer if statement we indicate that n::alltypes data member is active (simultaneously with ni::type and nf::type as the standard states) yet in the inner if we use nf::doublenode which is not a part of the common initial sequence.

Can somebody clarify this issue?

  • 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-10T11:00:42+00:00Added an answer on June 10, 2026 at 11:00 am

    it is permitted to inspect the common initial part of [several structures that share a common initial sequence]

    Using the provided example, this part of the specification is saying that since each possible member type of the union has an int as the initial field, you can access that common initial field using any of the member types, even after the variable has been initialized/used as one of the specific member types.

    This is just what the example does: it accesses the initial int as the alltypes member of an n, after having initialized following fields as an nf, and then goes on to access the doublenode field of an nf, all using the same variable.

    Using the union as one of the possible types doesn’t force it into some sort of structure: this is how unions work.

    Note that this guarantee has been around for some time: essentially the same text is found in the ANSI specification, section: 3.3.2.3 Structure and union members.

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

Sidebar

Related Questions

I know the C11 standard is only a month old, but the drafts for
Is there anything in the C standard (I guess at the moment that's C99
I was wondering about the following: is the new _Alignas alignment specifier in C11
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
C11 supports anonymous structures, like so: struct Foo { struct { size_t x, y;
Working in C11, the following struct: struct S { unsigned a : 4; _Bool
Anonymous structs have been added in the C11 standard, so typedef struct { struct
In C there's C89, C99, and C11; what about C++? Is there any upgrade
I have been using a driver to test one of my data structures(Binary Search
Why is there no UTF-8 character literal in C11 or C++11 even though there

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.