我有一个结构体,其中包含两个相同类型的其他结构体,我想将其初始化为两个都为NULL。我该怎么做?我尝试了下面的代码,但在使用gcc编译器时会出现警告。
#include <stdio.h>
typedef struct Segment {
int microseconds;
} Segment;
typedef struct Pair {
Segment mark;
Segment space;
} Pair;
int main()
{
Pair mark_and_space = { .mark = NULL, .space = NULL };
return 0;
}
编译器警告:
main.c:14:5: warning: initialization makes integer from pointer without a cast [enabled by default]
Pair mark_and_space = { NULL, NULL };
^
main.c:14:5: warning: (near initialization for 'mark_and_space.mark.microseconds') [enabled by default]
main.c:14:5: warning: initialization makes integer from pointer without a cast [enabled by default]
main.c:14:5: warning: (near initialization for 'mark_and_space.space.microseconds') [enabled by default]