由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - how to initialize this struct.
相关主题
什么时候写程序要注意这个问题?[合集] Interview Question
C 中的typedef 一问ask a question about struct in C programming
古德霸:协议确定了,请你确认typedef
为啥有人喜欢把_s结尾的结构typedef成_t结尾的,有讲究么?typedef struct的问题
sizeof()的问题一个简单的C编程问题
请教函数 INIT 怎么能free memory有段c++代码看不懂
difference between FILE and struct FILE请教一个c++ 里functor的问题
请问可以这样定义struct吗?问个编程,系统,网络有关的综合问题。
相关话题的讨论汇总
话题: struct话题: initialize话题: long话题: int32话题: instance
进入Programming版参与讨论
1 (共1页)
l*l
发帖数: 26
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
l*l
发帖数: 26
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;

1 (共1页)
进入Programming版参与讨论
相关主题
问个编程,系统,网络有关的综合问题。sizeof()的问题
typedef 的一个问题请教函数 INIT 怎么能free memory
请教一个rpcgen的问题difference between FILE and struct FILE
One question about Void pointer请问可以这样定义struct吗?
什么时候写程序要注意这个问题?[合集] Interview Question
C 中的typedef 一问ask a question about struct in C programming
古德霸:协议确定了,请你确认typedef
为啥有人喜欢把_s结尾的结构typedef成_t结尾的,有讲究么?typedef struct的问题
相关话题的讨论汇总
话题: struct话题: initialize话题: long话题: int32话题: instance