What is the scope of a pragma directive? For example, if I say #pragma warning(disable: 4996)
in a header file A that is included from a different file B, will that also disable all those warnings inside B? Or should I enable the warning at the end of file A again?
相关问题
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
- What uses more memory in c++? An 2 ints or 2 funct
相关文章
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- How to add external file to application files ( cl
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- Selecting only the first few characters in a strin
- What exactly do pointers store? (C++)
- Converting glm::lookat matrix to quaternion and ba
Pragmas are specific for the compiler and platform in use. So the best bet is to look at compiler's documentation.
For IBM compilers, for example:
Generally, pragma should have effect right after its declaration, no matter from what header it comes, until the end of translation unit. However, there are some pragmas that affect the whole program. For example, Microsoft-specific "link" pragma that adds dependency on some library to the translation unit and all its "users".
It is till the end of the translation unit. Informally, a TU is the source file with its include files.
The usual pattern is this:
for example
Yes, it will also disable the warnings inside B.
A translation unit is a .cpp file and all its included files expanded out into one great big file. That pragma will last to the end of the translation unit, or until another #pragma warning changes the setting. Or, if you're compiler supports #pragma push and #pragma pop, it will last until the next #pragma pop.
'#pragma push' and '#pragma pop' allow you to create scopes. #pragma warnings within such a scope will apply to the end of the scope.