How to remove GCC warning in #pragma area?

How to remove GCC warning on #pragma region ? I added pragma region to easily view the code, but it reports warnings on #pragma region . I am using Visual Studio 2010.

+6
source share
4 answers

gcc has this warning flag:

-Wunknown-pseudo-comments Warn when the #pragma directive is encountered that is not understood by GCC. If this command line option is used, warnings will even be issued for unknown pragmas in the system header files. This is not the case if warnings were only enabled using the -Wall command line option.

And as usual, you can deny this, that is, unknown pragmas will not be warned. That is, use -Wno-unknown-pragmas .

Note that -Wno-unknown-pragmas should appear after any command line flags that enable this warning, for example -Wall - this also disables warnings for all unknown pragmas, so use with caution.

+8
source

Do not use it in GCC? :)

The simplest solution that I can think of now is to use preprocessor conventions for it:

 #ifndef __GNUC__ #pragma region #endif // Stuff... #ifndef __GNUC__ #pragma endregion #endif 

Not very pretty or readable, but will make the code compile without warning in GCC.

+6
source
 #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunknown-pragmas" ... Code using Unknown pragmas ... #pragma GCC diagnostic pop 
+4
source

This seems to be a pragma for MSVC, so you should use

 #ifdef _MSC_VER #pragma region #endif <code here> #ifdef _MSC_VER #pragma endregion #endif 
+3
source

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


All Articles