【发布时间】:2019-02-11 18:32:29
【问题描述】:
其中一些可能是重复的,但我很抱歉。
假设我有这个struct:
struct foo
{
int a;
int b;
int c;
};
1.如果struct foo类型对象被声明为具有自动存储持续时间并且没有初始化器,是否保证它的所有成员都会被强制初始化为零?
{
// other stuff
struct foo bar;
// other stuff
}
2.如果struct foo类型对象被声明为具有自动存储持续时间并且带有一些初始化器,是否保证成员,不是显式初始化,会被强制初始化为零吗?
{
// other stuff
struct foo bar = {.a = 1};
// other stuff
}
3. 如果struct foo 类型对象以具有自动存储期限的方式声明并使用复合文字 表达式,是否保证成员,其没有显式初始化,会被强制初始化为零吗?
{
// other stuff
func((struct foo){.a = 1});
// other stuff
}
非常感谢任何 C 标准参考!谢谢!
【问题讨论】:
标签: c struct initialization language-lawyer automatic-storage