Some of this may be a duplicate, but I am sorry for that.
Let's say I have this struct:
struct foo
{
int a;
int b;
int c;
};
1. If struct foo type object is declared in the way that it has automatic storage duration and without initializers, is it guaranteed that all it's members will be force initialized to zero?
{
// other stuff
struct foo bar;
// other stuff
}
2. If struct foo type object is declared in the way that it has automatic storage duration and with some initializers, is it guaranteed that members, which are not explicitly initialized, will be force initialized to zero?
{
// other stuff
struct foo bar = {.a = 1};
// other stuff
}
3. If struct foo type object is declared in the way that it has automatic storage duration and by using compound literal expression, is it guaranteed that members, which are not explicitly initialized, will be force initialized to zero?
{
// other stuff
func((struct foo){.a = 1});
// other stuff
}
Any C standard references are much appreciated! Thank you!
First of all, uninitialized variables with automatic storage will never be initialized. From The C11 standard (ISO/IEC 9899:2011 §6.7.9/10):
Then from this structure initialization reference:
And if we follow the "initialized implicitly" link we have:
So to answer your questions:
The links provided have references to the standard.