ç初始化采用铸造,这是危险的? [英] C initializer with cast, is this dangerous?
本文介绍了ç初始化采用铸造,这是危险的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
考虑以下几点:
struct Foo
{
char c;
int i;
};
void Bar(void)
{
struct Foo f = {0}; // use zero initializer
// do some stuff
f = (struct Foo) {'h', 1}; // copy different data into f, is this dangerous?
}
请问上述投被认为是危险?这是很好的风格?
Would the cast above be considered dangerous? Is this good style?
推荐答案
这不是一个风格问题;即code不会没有编译(结构美孚)
。这不是一个演员,它的语法被称为C99功能的一部分的复合文字的
It's not a matter of style; that code won't compile without the (struct Foo)
. It's not a cast, it's part of the syntax for a C99 feature known as a compound literal.
这篇关于ç初始化采用铸造,这是危险的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文