我有一個結構包含兩個相同類型的其他結構,我想初始化它有兩個NULL開始。我怎麼做?我已經嘗試了下面,但使用gcc獲取編譯器警告。如何初始化一個結構爲null?
#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]
變空爲0,因爲標記和空間類型爲int你是在讀 – Ihdina