sny
sny

Reputation: 415

#pragma warning(push) without #pragma warning(pop)

Using C++ Native solution in Visual Studio 2010.

#pragma warning (push) is used in the beginning of the cpp file, after all the includes. After that there are couple of disabled warning by #pragma warning(disable : XXXX).

What are possible consequences of omitting #pragma warning(pop) at the end of the file?

Thanks

Upvotes: 2

Views: 2079

Answers (2)

Adam Rosenfield
Adam Rosenfield

Reputation: 400562

If you have any other source files that #include that cpp file, then the warning state when compiling the outer file will be messed up -- it could fail to give warnings when the warnings were warranted.

Note, however, that #includeing a cpp file is considered bad form and a code smell; there are certain, rare, situations where it might be the right thing to do (such as a build system that #includes many source files into one to reduce compilation times, sort of like precompiled headers), but almost always it's the wrong thing to do, even if it manages to compile and link without errors.

If that source file is never #included anywhere else, then failing to have a #pragma warning(pop) will not have any adverse consequences, assuming the compiler doesn't complain about that mismatch in the first place.

Upvotes: 2

SinisterMJ
SinisterMJ

Reputation: 3509

Since this is a compiler only setting, it won't have any impact on the program itself. It may though screw up warnings for external includes.

Upvotes: 1

Related Questions