Component literal and assigned initialization warning from GCC, but not Clang

Compiling with gcc -std=c99 -Wextra this piece of code:

 #include <stdio.h> struct T { int a; int *b; int c; }; int main(void) { struct T t = {.b = ((int []){1, 1})}; printf("%d\n", tb[1]); return 0; } 

Gives me a warning:

 demo.c:11:12: warning: missing initializer for field 'c' of 'struct T' [-Wmissing-field-initializers] struct T t = {.b = ((int []){1, 1})}; ^ demo.c:6:9: note: 'c' declared here int c; ^ 

But the designated initializers must initialize the remaining elements to zero, even if they are skipped.

Why a warning? ( clang compiles the same piece of code without warning)

 gcc version 6.3.0 20170516 (Debian 6.3.0-18) clang version 3.8.1-24 (tags/RELEASE_381/final) 
+5
source share

Source: https://habr.com/ru/post/1275677/


All Articles