avatar
how to initialize this struct.# Programming - 葵花宝典
l*l
1
typedef struct __my_long_long{
union{
u_int64_t val;
struct{
u_int32_t low;
u_int32_t high;
};
}my_long_long_t;
my_long_lont_t instance = {
val: 0;
};
// This is reported error. How to initialize the "instance".
Thanks
avatar
l*l
2
Just find a document.
You can declare and initialize a union in the same statement by assigning an expression enclosed in curly braces. The expression is evaluated and assigned to the first field of the union.
So it should be :
my_long_long_t instance={0};

【在 l*l 的大作中提到】
: typedef struct __my_long_long{
: union{
: u_int64_t val;
: struct{
: u_int32_t low;
: u_int32_t high;
: };
: }my_long_long_t;
: my_long_lont_t instance = {
: val: 0;

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。