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:
Wasn’t this ugly macro specifically to shut up those compiler warnings?
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:
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)
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.