Jump to content
  • Advertisement

Archived

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

MetaKnight

Compiler Switch to Init all variables

This topic is 5224 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Does anyone know the sompiler switch to Init all variables? or how to do it in visual studio .net? I know it''s on by deafult for debug, but i want to add it to release. Thank you

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
That the certain compilers initialize certain variables to certain values in certain situations is purely a debugging aid.

Exactly what do you want the compiler to initizlse your variables to? A random value? INVALID_HANDLE_VALUE? 0? 0xFFFFFFFF? The answer is that the C++ standard doesn''t tell, so the compiler has no defined way of initializing variables.

Do the initialization yourself.

Share this post


Link to post
Share on other sites
Initialization should be done in your constructor, or when the variable is declared. Don''t rely on your compiler for that. What if the compiler initializes it to something you don''t want?

Share this post


Link to post
Share on other sites
Turn on compiler warnings, and then fix them. Make the compiler treat warnings as errors, and not actually complete until there are no warnings. The compiler will warn about use of uninitialized variables, when the right switches are turned on.

Warnings are your friends. Almost as good friends as the debugger.

Share this post


Link to post
Share on other sites
That actually reminds me of an interesting piece of code I saw once where the top of the header looked like this:


#pragma warning(disable : xxxx)
#pragma warning(disable : xxxx)
#pragma warning(disable : xxxx)
#pragma warning(disable : xxxx)
#pragma warning(disable : xxxx)
#pragma warning(disable : xxxx)
#pragma warning(disable : xxxx)
#pragma warning(disable : xxxx)
#pragma warning(disable : xxxx)
#pragma warning(disable : xxxx)
#pragma warning(disable : xxxx)
#pragma warning(disable : xxxx)
#pragma warning(disable : xxxx)
#pragma warning(disable : xxxx)
#pragma warning(disable : xxxx)
#pragma warning(disable : xxxx)
#pragma warning(disable : xxxx)
#pragma warning(disable : xxxx)
#pragma warning(disable : xxxx)
#pragma warning(disable : xxxx)
#pragma warning(disable : xxxx)
#pragma warning(disable : xxxx)
#pragma warning(disable : xxxx)
#pragma warning(disable : xxxx)
#pragma warning(disable : xxxx)
#pragma warning(disable : xxxx)
#pragma warning(disable : xxxx)
#pragma warning(disable : xxxx)


Why? Because the original programmer thought the warnings were "stupid". Oi.

Share this post


Link to post
Share on other sites
Not necessarily. There are some warnings generated by MSVC that are caused by their STL code (and possibly in other things too). Some of these warnings can be very annoying because they''ll show up in huge quantities or be really long messages so they''ll make it tougher to find the compiler errors in the list.

The particular offender I can think of off-hand is std::map. It throws warnings about symbol names being too long (because there''d be several indirections through classes, all of them requiring template parameters and so on) and once a symbol exceeds 255 characters (I think) the compiler will spit out a warning.

Changing the warning level can help but will disable other warnings you might actually want to see, so you can disable individual warnings to hide warnings like those and still see the ones you like. Though my std::map example isn''t a great one because the compiler seems to ignore the #pragmas that disable those specific warnings (it''s a known bug and I don''t remember if they fixed it in a service pack).

That said though, there''s still the possibility that that coder just didn''t want to see any warnings and disabled everyone he was getting instead of disabling them altogether...

-Auron

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:
Original post by Auron
Not necessarily. There are some warnings generated by MSVC that are caused by their STL code (and possibly in other things too). Some of these warnings can be very annoying because they''ll show up in huge quantities or be really long messages so they''ll make it tougher to find the compiler errors in the list.
Somewhat true. However with VC++ 7.1 and the latest STL this has been fixed.

Even with VC6 and the poor STL version shipped with that, you can have a single header file (such as stdafx) and disable warnings only for stl/windows header files, but compiler your own code on W4 without warnings. It''s probably a pain to fix for an existing project, but for a new project it''s very doable and strongly recommended.

Share this post


Link to post
Share on other sites
quote:
Original post by Anonymous Poster
Even with VC6 and the poor STL version shipped with that, you can have a single header file (such as stdafx) and disable warnings only for stl/windows header files, but compiler your own code on W4 without warnings. It''s probably a pain to fix for an existing project, but for a new project it''s very doable and strongly recommended.


You can also re-enable warnings with #pragma in VC after they have been disabled.

Share this post


Link to post
Share on other sites
well my code is fine, i run with warning level 4(the highest) and i fix them all, but- im usign a physics library called tokamak, and in release mode, everything get's messed up. I just wanted to turn that on and see if that was the problem. I never compile with a warning, unless it's not from me.

[edited by - MetaKnight on June 6, 2004 7:13:12 PM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!