I am watching a talk about modern C - this is timed link - the presenter showed the following C struct initializer:
typedef struct v2
{
float x, y;
} v2;
v2 v = { .x = 1.0f };
v = (v2) { .y = 1.0f };
But when I compile this code, I got the following warn and error:
$>gcc test.c
test.c:6:1: warning: data definition has no type or storage class
6 | v = (v2) { .y = 1.0f };
| ^
test.c:6:1: warning: type defaults to ‘int’ in declaration of ‘v’ [-Wimplicit-int]
test.c:6:1: error: conflicting types for ‘v’
test.c:4:4: note: previous definition of ‘v’ was here
4 | v2 v = { .x = 1.0f };
| ^
test.c:6:5: error: incompatible types when initializing type ‘int’ using type ‘v2’ {aka ‘struct v2’}
6 | v = (v2) { .y = 1.0f };
| ^
So is the presenter wrong? I am using gcc v9.4.0, the default at Ubuntu 20.