Re: Locally-declared static variables in optimized code. by Norbert
Norbert
Sun Oct 21 02:34:36 PDT 2007
Jeffâ? Relf schrieb:
> #pragma warning( disable: 4007 4127 4430 4508 )
I wonder why all of your code samples contain this #pragma warning to disable a
list of (in my view valid) compiler warnings? Wouldn't it be better to adjust
your code accordingly?
> WinMain( int, int, int, int ) {
I belive the correct WinMain signature is:
#include <windows.h>
int WINAPI WinMain (HINSTANCE, HINSTANCE, LPSTR, int)
which removes warnings 4430 and 4007.
If you do not like to include winmain for these small demo projects, you could use
int __stdcall WinMain()
instead.
> while ( 1 ) {
As a warning-free pattern for an endless loop (which is also recognised by tools
as Lint) you can use:
for (;;) {
which removes warning 4127.
> static double X ;
>
> // Breaking here, the debugger can't see what X contains.
> if ( ++ X > 5 ) return ;
Since WinMain returns an integer exit code, you should return a value, like
if ( ++x > 5) return 0;
which removes warning 4508 (or even error 2561 after fixing warning 4430 above)
> } }
>
Norbert