Is using #pragma warning push/pop the right way to temporarily alter warning level?

This will work with multiple compilers (and different versions of compilers). Header “push” #if defined(__clang__) # pragma clang diagnostic push #endif #if defined(_MSC_VER) # pragma warning(push) #endif #if defined(YOUR_FAVORITE_COMPILER) # pragma your compiler push warning #endif Header “pop” #if defined(__clang__) # pragma clang diagnostic pop #endif #if defined(_MSC_VER) # pragma warning(pop) #endif Some warning #if … Read more

What does “#pragma comment” mean?

#pragma comment is a compiler directive which indicates Visual C++ to leave a comment in the generated object file. The comment can then be read by the linker when it processes object files. #pragma comment(lib, libname) tells the linker to add the ‘libname’ library to the list of library dependencies, as if you had added … Read more

Use of #pragma in C

#pragma is for compiler directives that are machine-specific or operating-system-specific, i.e. it tells the compiler to do something, set some option, take some action, override some default, etc. that may or may not apply to all machines and operating systems. See msdn for more info.

Tell gcc to specifically unroll a loop

GCC gives you a few different ways of handling this: Use #pragma directives, like #pragma GCC optimize (“string”…), as seen in the GCC docs. Note that the pragma makes the optimizations global for the remaining functions. If you used #pragma push_options and pop_options macros cleverly, you could probably define this around just one function like … Read more

Selectively disable GCC warnings for only part of a translation unit

This is possible in GCC since version 4.6, or around June 2010 in the trunk. Here’s an example: #pragma GCC diagnostic push #pragma GCC diagnostic error “-Wuninitialized” foo(a); /* error is given for this one */ #pragma GCC diagnostic push #pragma GCC diagnostic ignored “-Wuninitialized” foo(b); /* no diagnostic for this one */ #pragma GCC … Read more

tech