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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T20:18:58+00:00 2026-05-12T20:18:58+00:00

I could do struct initialization with code: struct struct_type_id struct_name_id = { value1, value2,

  • 0

I could do struct initialization with code:

struct struct_type_id struct_name_id = { value1, value2, value3 };

but could not with:

struct struct_type_id struct_name_id;
struct_name_id = { value1, value2, value3 };

why I could do it with the former,but could not with the latter with gcc,g++,vc2008,vc6?In other words,why the c/c++ programming language do not support this syntax?

thanks.

  • 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-12T20:18:58+00:00Added an answer on May 12, 2026 at 8:18 pm

    The first statement creates a variable initialized to the given values, i.e., these values are built in memory and stored directly in the program executable in that variable address (for globals) or ready for memory copy (for stack variables).

    The second statement of the second block is very different. Although it looks similar, it is an assign expression. It means that the RHS of the equals operator is an expression that is evaluated (independently of what is in the LHS of =), and then passed to the = operator. Without proper context, {...} doesn’t have any meaning.

    In C99, you can do this:

    struct_name_id = (struct struct_type_id){ value1, value2, value3 };
    

    Now the RHS of the equals operator is a valid expression, since there is proper context for the compiler to know what is in {...}.

    In C++11, the syntax is:

    struct_name_id = struct_type_id{ value1, value2, value3 };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I found some struct initialization code yesterday that threw me for a loop. Here's
Could you please help me how to format a struct timeval instance to human
Could you please have a look at my code below. #!C:\Perl\bin\perl.exe use strict; use
Could somebody please name a few. I could given time, but this is for
I was converting a struct to a class so I could enforce a setter
Could a variable of Data be used as a map key? struct Data {
Could someone please explain the difference in how the 2 snippets of code are
Consider this smallest example (I could think of): struct Bar; struct Foo { Bar*
In our code we used to have something like this: *(controller->bigstruct) = ( struct
Consider the following code: struct I { SomeInternalState m_internalState; }; struct S { I

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.