#include "file" means taking the header file and putting all its contents in place of the #include line.
We typically used headers to identify types and to add forward declarations to source files. defining the same type twice in a file (circular inclusion always causes it) gives a compilation error, so we use #ifndef or #pragma once . (or both)
But we can also put repeating code and macros and include it several times, even in the same file. in this case, we will not use #ifndef and #pragma once . If you do this, you must be very careful and do it only if you know what you are doing.
For example: If on any operating system that invokes a specific system function (or even an ac macro like: offsetof ), a lot of warnings occur and this bothers you, and you are sure that your code is good, but you do not want to disable everything warnings that you have in the whole project or file, you just want to disable it when you call a specific function.
//suppress the warnings: #if defined(__GNUC__) #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wreorder" #pragma GCC diagnostic ignored "-Wunused-function" #pragma GCC diagnostic ignored "-Wunused-variable" #pragma GCC diagnostic ignored "-Wsign-compare" #pragma GCC diagnostic ignored "-Wmaybe-uninitialized" #pragma GCC diagnostic ignored "-Wsequence-point" #endif #endif // __GNUC__ //here you call the function... func(x,y,z); //unsupress: bring back the warnings to normal state #if defined(__GNUC__) #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) #pragma GCC diagnostic pop #endif #endif // __GNUC__
This will make your code look very dirty, especially if you call the function several times.
One possible solution (I do not propose that this is better ...) is to make 2 headers, one to suppress warnings and the other to cancel suppression.
In this case, your code might look like this:
#include "suppress.h" func(x,y,z); #include "unsuppress.h"
SHR
source share