GNOME Bugzilla – Bug 519026
G_STMT_START/G_STMT_END test a non-existent preprocessor symbol
Last modified: 2009-02-12 02:13:33 UTC
HAVE_DOWHILE_MACROS is never defined since config.h is not included by gmacros.h. It is annoying because the if/else fallback triggers a compiler warning: === #include <glib.h> #define FOO() G_STMT_START{ }G_STMT_END int main (int argc, char **argv) { if (1) FOO(); return 0; } === $ cc -Wall -std=c99 `pkg-config --cflags --libs glib-2.0` -o test test.c cc1: warnings being treated as errors test.c: In function ‘main’: test.c:7: warning: suggest explicit braces to avoid ambiguous ‘else’
That is pretty broken, indeed. What needs to happen here is: a) add a G_ prefix to the macro b) define it in glibconfig.h, not in config.h c) include glibconfig.h in gmacros.h Tim ?
It's 2008, is anything that doesn't support do/while(0) even relevant anymore?
(In reply to comment #1) > That is pretty broken, indeed. > > What needs to happen here is: > > a) add a G_ prefix to the macro > > b) define it in glibconfig.h, not in config.h > > c) include glibconfig.h in gmacros.h > > > Tim ? i completely agree with yosh, there should be nothing out there that has problems with do{}while(0), which is why i used that already for some assertion macros. i think we can simply switch G_STMT* to always say do{}while(0) at this point. any takers up for this? tbf?
This too will rot forever, right?
2008-05-22 10:49:37 Tim Janik <timj@imendio.com> * glib/gmacros.h: implement G_STMT_START and G_STMT_END with do{}while(0), which is believed to be widely portable, fixes: Bug 519026 - G_STMT_START/G_STMT_END test a non-existent preprocessor symbol
*** Bug 507349 has been marked as a duplicate of this bug. ***