Will this warning create any problem in runtime?
ext.h(180) : warning C4201: nonstandard extension used : nameless struct/union
This is when you have a union or struct without a name, e.g.:
typedef struct
{
union
{
int a;
int b;
}; // no name
int c;
} MyStruct;
MyStruct m;
m.a = 4;
m.b = 6; //overwrites m.a
m.c = 8;
It allows you to access members of the union as if they were members of the struct. When you give the union a name (which is what the standard requires), you must access a
and b
through the name of the union instead:
typedef struct
{
union
{
int a;
int b;
} u;
int c;
}
MyStruct m;
m.u.a = 4;
m.u.b = 6; // overwrites m.u.a
m.c = 8;
It is not an issue as long as you compile your code using compilers that share this extension, it is only a problem when you compile your code using compilers that don't, and because the standard doesn't require this behaviour, a compiler is free to reject this code.
Edit: As pointed out by andyn, C11 explicitly allows this behaviour.
Well it is a MSVC warning, which tells you that you are using an compiler specific language extension. so you can check this.
nonstandard extension used : nameless struct/union
Under Microsoft extensions (/Ze), you can specify a structure without a declarator as members of another structure or union. These structures generate an error under ANSI compatibility (/Za).
// C4201.cpp
// compile with: /W4
struct S
{
float y;
struct
{
int a, b, c; // C4201
};
} *p_s;
int main()
{
}
If you are not bothered about portability of your code. i.e: Your target platform is only MSVC then simply ignore the warning.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With