#### Archived

This topic is now archived and is closed to further replies.

# MSVC STL and warnings

## Recommended Posts

Kylotan    10008
A little tip that one or two of you may find useful: The STL distributed with MSVC 5 and 6 causes a lot (and I mean a lot) of level 4 warnings, making it difficult to use this warning level in many C++ projects. One solution to this is to edit all the standard headers (the ones in the include directory that lack a .H extension) by adding #pragma warning(push, 3) in the #ifdef _MSC_VER section at the top, and #pragma warning(pop) in the corresponding #ifdef _MSC_VER section at the bottom. Adding these two simple lines of code should ensure that the warning level is set at 3 when compiling the STL headers, even if the rest of your project is compiling at warning level 4, which is useful for catching more subtle bugs. (Note: I''ve not found any problems with doing this, but I can''t guarantee it''ll work all the time. Back up your headers if you don''t feel confident that you can take out those 2 lines easily enough in the event of difficulty.) PS. While you''re altering those header files (and even if you''re not), apply the fixes from the site labelled MSVC Fixes in my signature. [ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost ]

##### Share on other sites
Shannon Barber    1681
They say v3.08 compiles with no warnings at level 4 - did they just push/pop the warning level, or did they actually address the warnings?

##### Share on other sites
Kylotan    10008
I do not know, since I am too poor to buy the update Hopefully they actually fixed most of them, although a massive proportion of the errors are signed/unsigned mismatches where they''re comparing a signed value to an unsigned ''size_type''. It might not be practical or efficient for them to force a cast in these cases when they can be pretty sure the values are in range if their algorithm is correct. So I wouldn''t be surprised if they just turned a few of the warnings off.

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost ]

##### Share on other sites
Void    126
The dinkumware STL still uses #pragma''s push and pops to hide warnings, but sadly some of them still gets through sometimes.

The compiler should have a flag to disable a particular type of warning.

##### Share on other sites
Oluseyi    2112
quote:
Original post by Void
The compiler should have a flag to disable a particular type of warning.

#pragma warning( disable : 4786 )

[ GDNet Start Here | GDNet FAQ | MS RTFM | STL | Google ]
Thanks to Kylotan for the idea!