【发布时间】:2014-11-30 20:11:34
【问题描述】:
我有闲置的结构:
struct lshort_sched_param {
int requested_time;
int level;
};
struct sched_param {
union {
int sched_priority;
struct lshort_sched_param lshort_params;
};
};
我正在尝试像这样创建它们的新实例:
struct lshort_sched_param *l = {2 ,1};
struct sched_param *p = {3, l};
并得到一些警告:
test.c:5: warning: initialization makes pointer from integer without a cast
test.c:5: warning: excess elements in scalar initializer
test.c:5: warning: (near initialization for `l')
test.c:6: warning: initialization makes pointer from integer without a cast
test.c:6: warning: excess elements in scalar initializer
test.c:6: warning: (near initialization for `p')
谁能帮我弄清楚?
【问题讨论】:
-
你的代码有各种各样的问题。为什么要声明一个指针并将其初始化为
struct? -
请注意,您在此处声明了一个 anonymous 联合。声明一个标识符来配合它呢?如
union { ... } foo;。
标签: c struct compiler-warnings unions