I want to initialize a struct element, split in declaration and initialization.
(我想初始化一个struct元素,拆分为声明和初始化。)
This is what I have: (这就是我所拥有的:)
typedef struct MY_TYPE {
bool flag;
short int value;
double stuff;
} MY_TYPE;
void function(void) {
MY_TYPE a;
...
a = { true, 15, 0.123 }
}
Is this the way to declare and initialize a local variable of MY_TYPE
in accordance with C programming language standards (C89, C90, C99, C11, etc.)?
(这是按照C编程语言标准(C89,C90,C99,C11等)声明和初始化MY_TYPE
局部变量的MY_TYPE
吗?)
Or is there anything better or at least working? (还是有什么更好的方法,或者至少可以起作用?)
Update I ended up having a static initialization element where I set every subelement according to my needs.
(更新我最终得到了一个静态初始化元素,在其中根据需要设置了每个子元素。)
ask by cringe translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…