zstd icon indicating copy to clipboard operation
zstd copied to clipboard

Disabled assert() could use its argument to avoid unused variable warnings

Open terrelln opened this issue 3 years ago • 1 comments

Test this construction for disabling assertions:

#define assert(condition)      \
    do {                       \
        if (0) {               \
            (void)(condition); \
        }                      \
    } while (0)

Additionally, do the same for RAWLOG() and DEBUGLOG() when DEBUGLEVEL < 2.

This would avoid unused variable warnings that show up in production.

terrelln avatar Nov 17 '21 19:11 terrelln

Note : this construction relies on the compiler doing a good DCE job. While this is most likely the case for most modern and mainstream compilers using optimization settings, it's more difficult to be sure about that with regards to the larger C compiler ecosystem.

An example of uncommon compiler (yet not completely fringe) which may have troubles with DCE could be tcc.

Cyan4973 avatar Nov 17 '21 20:11 Cyan4973