implement G_STMT_START and G_STMT_END with do{}while(0), which is believed
author10:49:37 Tim Janik <timj@imendio.com>
Thu, 22 May 2008 08:53:15 +0000 (08:53 +0000)
committerTim Janik <timj@src.gnome.org>
Thu, 22 May 2008 08:53:15 +0000 (08:53 +0000)
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

svn path=/trunk/; revision=6922

ChangeLog
glib/gmacros.h

index 7f748bc..4e12923 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+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
+
 2008-05-20  Behdad Esfahbod  <behdad@gnome.org>
 
        Bug 501651 – Update glib/libcharset
index 01650a0..395363d 100644 (file)
 #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