From 0782d697e5b2809f754b4416ffa7c1ae3a82c686 Mon Sep 17 00:00:00 2001 From: "10:49:37 Tim Janik" Date: Thu, 22 May 2008 08:53:15 +0000 Subject: [PATCH] implement G_STMT_START and G_STMT_END with do{}while(0), which is believed 2008-05-22 10:49:37 Tim Janik * 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 svn path=/trunk/; revision=6922 --- ChangeLog | 6 ++++++ glib/gmacros.h | 31 ++++++++----------------------- 2 files changed, 14 insertions(+), 23 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7f748bc..4e12923 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2008-05-22 10:49:37 Tim Janik + + * 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 + 2008-05-20 Behdad Esfahbod Bug 501651 – Update glib/libcharset diff --git a/glib/gmacros.h b/glib/gmacros.h index 01650a0..395363d 100644 --- a/glib/gmacros.h +++ b/glib/gmacros.h @@ -216,31 +216,16 @@ #define G_STRUCT_MEMBER(member_type, struct_p, struct_offset) \ (*(member_type*) G_STRUCT_MEMBER_P ((struct_p), (struct_offset))) -/* Provide simple macro statement wrappers (adapted from Perl): - * G_STMT_START { statements; } G_STMT_END; - * can be used as a single statement, as in - * if (x) G_STMT_START { ... } G_STMT_END; else ... - * - * When GCC is compiling C code in non-ANSI mode, it will use the - * compiler __extension__ to wrap the statements wihin `({' and '})' braces. - * When compiling on platforms where configure has defined - * HAVE_DOWHILE_MACROS, statements will be wrapped with `do' and `while (0)'. - * For any other platforms (SunOS4 is known to have this issue), wrap the - * statements with `if (1)' and `else (void) 0'. +/* Provide simple macro statement wrappers: + * G_STMT_START { statements; } G_STMT_END; + * This can be used as a single statement, like: + * if (x) G_STMT_START { ... } G_STMT_END; else ... + * This intentionally does not use compiler extensions like GCC's '({...})' to + * avoid portability issue or side effects when compiled with different compilers. */ #if !(defined (G_STMT_START) && defined (G_STMT_END)) -# if defined (__GNUC__) && !defined (__STRICT_ANSI__) && !defined (__cplusplus) -# define G_STMT_START (void) __extension__ ( -# define G_STMT_END ) -# else /* !(__GNUC__ && !__STRICT_ANSI__ && !__cplusplus) */ -# if defined (HAVE_DOWHILE_MACROS) -# define G_STMT_START do -# define G_STMT_END while (0) -# else /* !HAVE_DOWHILE_MACROS */ -# define G_STMT_START if (1) -# define G_STMT_END else (void) 0 -# endif /* !HAVE_DOWHILE_MACROS */ -# endif /* !(__GNUC__ && !__STRICT_ANSI__ && !__cplusplus) */ +# define G_STMT_START do +# define G_STMT_END while (0) #endif /* Allow the app programmer to select whether or not return values -- 2.7.4