Skip to content

Prefer `do {} while (0);` over `while (0);`

Michael Bradshaw requested to merge mjbshaw/dav1d:dowhile into master

Sometimes developers forget a trailing semicolon. If this happens with a macro like #define FOO while (0), then:

FOO
do_stuff();

is syntactically valid and will result in do_stuff() never being executed. Using #define FOO do {} while (0) helps protect against this since the above code is no longer syntactically valid.

I know this is unlikely to be a problem in the real world since dav1d is tested on multiple platforms (where these are real functions instead of macros).

Edited by Michael Bradshaw

Merge request reports

Loading