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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T16:21:10+00:00 2026-06-18T16:21:10+00:00

Given the following: struct example_struct { char c; int i; }; Is any the

  • 0

Given the following:

struct example_struct
{
  char c;
  int i;
};

Is any the following initializer syntax valid in C99?

Syntax example #1

struct example_struct example = { 'a', .i = 1};

Syntax example #2

struct example_struct example = { .c = 'a', 1};

I am writing a simple struct parser and in my testing, this does not cause a compiler error using XCode 4.2. I would like my parser to be C99 compliant. My understanding (without a standard reference) is that a struct initializer should either have all unnamed or named (i.e. designated) members.

Should syntax example #1 and #2 be compiler errors?

If the examples are valid, what are the rules for the initialization syntax?

UPDATED QUESTION EXAMPLES

struct example_struct_3
{
  char c;
  int i;
  float f;
};

struct example_struct_3 example = { .i = 1, 1.0};

In the same main question, how would example three work? I’m mainly confused about the arbitrary ordering of designated initializers with standard initializers.

  • 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-18T16:21:11+00:00Added an answer on June 18, 2026 at 4:21 pm

    Both your initializations example 1 and 2 are valid C99/C11 initializations. You can mix designation initializers and non-designation initializers in an initializer list.

    EDIT: regarding your new example 3, the initialization is also valid. After initialization, example.c has value 0, example.i has value 1 and example.f has value (float) 1.0.

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

Sidebar

Related Questions

Given the following example: class AnonymousSession << Struct.new(:location, :preferences) def valid? ... end def
Given the following contrived example code: struct abc { int x[5]; int y[5]; };
Is the following example a valid complete translation unit in C? struct foo; struct
Given the following code: final class retVal { int photo_id; } Gson gson =
Given the following structure: struct nmslist_elem_s { nmptr data; struct nmslist_elem_s *next; }; typedef
Suppose I have the following: typedef struct { int itemSize; int count; void *list;
I'm currently working on a Database which requires the following functionality: For example given
Given the following code snippet from Anthony Williams . A very basic tuple example
Possible Duplicate: Size of struct with a single element Given any type A and
I have the following code: #include <iostream> using namespace std; struct S { S(int

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.