glib r6922 - in trunk: . glib



Author: timj
Date: Thu May 22 08:53:15 2008
New Revision: 6922
URL: http://svn.gnome.org/viewvc/glib?rev=6922&view=rev

Log:
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




Modified:
   trunk/ChangeLog
   trunk/glib/gmacros.h

Modified: trunk/glib/gmacros.h
==============================================================================
--- trunk/glib/gmacros.h	(original)
+++ trunk/glib/gmacros.h	Thu May 22 08:53:15 2008
@@ -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



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]