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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T00:25:46+00:00 2026-06-05T00:25:46+00:00

For example, if somestruct has three integer members, I had always thought that it

  • 0

For example, if somestruct has three integer members, I had always thought that it was OK to do this in C (or C++) function:

somestruct s = {123,};

The first member would be initialized to 123 and the last two would be initialized to 0. I often do the same thing with automatic arrays, writing int arr[100] = {0,}; so that all integers in an array are initialized to zero.

Recently I read in the GNU C Reference Manual that:

If you do not initialize a structure variable, the effect depends on
whether it is has static storage (see Storage Class Specifiers) or
not. If it is, members with integral types are initialized with 0 and
pointer members are initialized to NULL; otherwise, the value of the
structure’s members is indeterminate.

Can someone please tell me what the C and C++ standards say regarding partial automatic structure and automatic array initialization? I do the above code in Visual Studio without a problem but I want to be compatible with gcc/g++, and maybe other compilers as well. 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-06-05T00:25:48+00:00Added an answer on June 5, 2026 at 12:25 am

    The linked gcc documentation does not talk of Partial Initialization it just talks of (Complete)Initialization or No Initialization.

    What is partial Initialization?

    The standards do not define Partial initialization of objects, either there is Complete initialization or No-initialization. Partial Initialization is a non-standard terminology which commonly refers a situation where you provide some initializers but not all i.e: Fewer initializers than the size of the array or the number of structure elements being initialized.

    Example:

    int array[10] = {1,2};                    //Case 1:Partial Initialization
    

    What is (Complete)Initialization or No Initialization?

    Initialization means providing some initial value to the variable being created at the same time when it is being created. ie: in the same code statement.

    Example:

    int array[10] = {0,1,2,3,4,5,6,7,8,9};    //Case 2:Complete Initialization
    int array[10];                            //Case 3:No Initialization
    

    The quoted paragraph describes the behavior for Case 3.

    The rules regarding Partial Initialization(Case 1) are well defined by the standard and these rules do not depend on the storage type of the variable being initialized.
    AFAIK, All mainstream compilers have 100% compliance to these rules.


    Can someone please tell me what the C and C++ standards say regarding partial automatic structure and automatic array initialization?

    The C and C++ standards guarantee that even if an integer array is located on automatic storage and if there are fewer initializers in a brace-enclosed list then the uninitialized elements must be initialized to 0.

    C99 Standard 6.7.8.21

    If there are fewer initializers in a brace-enclosed list than there are elements or members of an aggregate, or fewer characters in a string literal used to initialize an array of known size than there are elements in the array, the remainder of the aggregate shall be initialized implicitly the same as objects that have static storage duration.


    In C++ the rules are stated with a little difference.

    C++03 Standard 8.5.1 Aggregates
    Para 7:

    If there are fewer initializers in the list than there are members in the aggregate, then each member not explicitly initialized shall be value-initialized (8.5).
    [Example:

     struct S { int a; char* b; int c; };
     S ss = { 1, "asdf" };
    

    initializes ss.a with 1, ss.b with "asdf", and ss.c with the value of an expression of the form int(), that is,0. ]

    While Value Initialization is defined in,
    C++03 8.5 Initializers
    Para 5:

    To value-initialize an object of type T means:
    — if T is a class type (clause 9) with a user-declared constructor (12.1), then the default constructor for T is called (and the initialization is ill-formed if T has no accessible
    default constructor);
    — if T is a non-union class type without a user-declared constructor, then every non-static
    data member and base-class component of T is value-initialized;
    — if T is an array type, then each element is value-initialized;
    — otherwise, the object is zero-initialized

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

Sidebar

Related Questions

Example: var sessions = require('sessions'); function load_session(req) { sessions.load(sid); } Now that the session
Example: A function that takes a function (that takes a function (that ...) and
Example: 20080807144334.410187-180 (-180 means GMT minus three hours. Rio de Janeiro in this case.)
/* * Example function for operating with dynamic arguments */ function something(){ for(var i
Example: puts <<BLOCK ... BLOCK with BLOCK being any other identifier that doesn't clash
// example-1: GetStringUTFChars() public class Prompt { // native method that prints a prompt
example: NSString *day = [[NSString stringWithFormat:@السبت];and i think the representation of this string in
Example class code: <?php class example { public function forExample() { return true; }
Example I have this array: @packages = [2, [4, 2, 1], 4, [4,2], [5,
Example of function: call getThings(amount, place, limit, marginError) SYNOPSIS: CALL getThings(4, PA, 3, 1.2);

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.