summaryrefslogtreecommitdiff
path: root/glib/gmacros.h
diff options
context:
space:
mode:
author10:49:37 Tim Janik <timj@imendio.com>2008-05-22 08:53:15 +0000
committerTim Janik <timj@src.gnome.org>2008-05-22 08:53:15 +0000
commit0782d697e5b2809f754b4416ffa7c1ae3a82c686 (patch)
tree7eaa8e695e6925e58d8f88433223b301efe52ee4 /glib/gmacros.h
parent64e1b6d84fd729b3f2489837acd05821794094ff (diff)
downloadglib-0782d697e5b2809f754b4416ffa7c1ae3a82c686.tar.gz
implement G_STMT_START and G_STMT_END with do{}while(0), which is believed
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
Diffstat (limited to 'glib/gmacros.h')
-rw-r--r--glib/gmacros.h31
1 files changed, 8 insertions, 23 deletions
diff --git a/glib/gmacros.h b/glib/gmacros.h
index 01650a04d..395363d78 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