In Visual Studio 2013, the following code snippet generates the compile error
error C2440: 'initializing' : cannot convert from 'TestSubStruct' to 'int'
#include <stdio.h>
typedef struct TestSubStruct {
int test;
} TestSubStruct;
typedef struct TestStruct {
TestSubStruct sub;
} TestStruct;
int main(int argc, char* argv[])
{
TestSubStruct r = {0};
TestStruct vp = { .sub = r}; // this line causes the error
return 0;
}
This can easily be rewritten so that it compiles, but what I want to know is why the code doesn't compile as is. Does it violate the specification for static initializers somehow? Is this just an issue with MSVC or do other compilers fail to build this as well?
EDIT: It seems from the commenters that this is an MSVC issue. In that case, my question is: what are the exact limitations of MSVC 2013's support for static initializers?