I want to keep any other checks -Wpedantic
does but lose the warning about unnamed structs error: ISO C++ prohibits anonymous structs [-Wpedantic]
.
I want to be able to do the following:
union
{
struct
{
float x, y, z, w;
};
struct
{
float r, g, b, a;
};
float v[4];
};
I'm using C++11 and compiling with the -std=c++11
flag. I've read that C11 supports this feature, but I haven't seen any mention of it being supported in C++11.
I've come across mention of -fms-extensions
:
In this SO question about C for which it is the accepted answer
In the GCC documentation for the flag's use when compiling C++ which doesn't give very many details
I tried the flag and it doesn't appear to have any effect (no matter the permutation of ordering between -fms-extensions
and -Wpedantic
).
Thanks to the comments I've found the following:
Details about why unnamed classes/structs are not fully conformant with the standard
A post that claims my example code relies on undefined behavior
I'd still like to know if there is a method of enabling this gcc extension (which all compilers I know of have) that will disable the warning. Or is -Wpedantic
all or nothing?
To suppress this warning use the unused attribute (see Variable Attributes). This warning is also enabled by -Wunused , which is enabled by -Wall . Warn whenever a static function is declared but not defined or a non-inline static function is unused. This warning is enabled by -Wall .
To produce only the compiled code (without any linking), use the -C option.
fPIC option in GCC enables the address of shared libraries to be relative so that the executable is independent of the position of libraries. This enables one to share built library which has dependencies on other shared libraries. fPIC stands for "force Position Independent Code".
Use the command-line option -O0 (-[capital o][zero]) to disable optimization, and -S to get assembly file. Look here to see more gcc command-line options.
You can disable -Wpedantic
temporarily, for example if you have old code in some include file:
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpedantic"
#include "old_header.hpp"
#pragma GCC diagnostic pop
Of course you could also do this on every occasion where you are using an anonymous struct to limit the scope where pedantic
is disabled, but when you are doing that you could as well just go ahead and fix the code itself :)
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