Avoid some warnings produced by static analysis tools

In my Visual Studio setup I have an static analysis tool that is run after each build and I get a lot of warnings like this:
The condition ‘(-1==xxx)’ of loop is always false.

This is generated by SDL_NULL_WHILE_LOOP_CONDITION macro from SDL_assert.h.
This macro is defined as follows:

Code:
#ifdef _MSC_VER /* stupid /W4 warnings. */
#define SDL_NULL_WHILE_LOOP_CONDITION (-1 == LINE)
#else
#define SDL_NULL_WHILE_LOOP_CONDITION (0)
#endif

A better definition that works on all compilers is:
Code:
#define SDL_NULL_WHILE_LOOP_CONDITION ((void)0, 0)

I would appreciate if someone is willing to put this change on Mercurial…

Wasn’t this ugly macro specifically to shut up those compiler warnings? :smiley:
The workarounds seem to get more and more obscure… and all this because
MSVC’s oh-so-clever static analysis doesn’t know about the
#define BLA do {
foo();
bar();
etc } while(0);
pattern :-/Am 14.01.2014 19:28, schrieb ZyZyX:

In my Visual Studio setup I have an static analysis tool that is run
after each build and I get a lot of warnings like this:
The condition ‘(-1==xxx)’ of loop is always false.

This is generated by SDL_NULL_WHILE_LOOP_CONDITION macro from SDL_assert.h.
This macro is defined as follows:

Code:
#ifdef _MSC_VER /* stupid /W4 warnings. */
#define SDL_NULL_WHILE_LOOP_CONDITION (-1 == LINE)
#else
#define SDL_NULL_WHILE_LOOP_CONDITION (0)
#endif

A better definition that works on all compilers is:

Code:
#define SDL_NULL_WHILE_LOOP_CONDITION ((void)0, 0)

I would appreciate if someone is willing to put this change on Mercurial…


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

The initial macro is OK just to make MSVC to shut up, but in my case I get a lot of warnings from PVS Studio and I found out that for the following type of macros, all compilers and static analyzers (or at least the compilers that I use: GCC, CLANG, MSVC and RVCT) do not complain:
#define BLA do {
foo();
bar();
etc } while((void)0, 0)

For whatever it’s worth, I am in favour of this.

The loop condition ((void)0, 0) works in all compilers (it’s standard
C) and doesn’t generate warnings on any of the compilers and analyzers
that were tested. It’s definitely not an obscure workaround, but
actually a good replacement for an “ugly macro specifically to
shut the compiler up”. Considering that casting to void is common
practice to signal that a value is ignored, this is a clean solution,
and certainly an improvement over the current solution.