After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 648426 - (G_STATIC_ASSERT_EXPR) Add G_STATIC_ASSERT_EXPR()
(G_STATIC_ASSERT_EXPR)
Add G_STATIC_ASSERT_EXPR()
Status: RESOLVED DUPLICATE of bug 626549
Product: glib
Classification: Platform
Component: general
unspecified
Other Linux
: Normal enhancement
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2011-04-21 21:03 UTC by Behdad Esfahbod
Modified: 2011-05-22 17:10 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Behdad Esfahbod 2011-04-21 21:03:20 UTC
glib provides G_STATIC_ASSERT(cond) which expands to a typedef.  That's useful in global scope, but cannot be used, eg, in macros expanding to an expression or statement.  For example, from gatomic.h:

# define g_atomic_int_get(atomic) \
 ((void) sizeof (gchar [sizeof (*(atomic)) == sizeof (gint) ? 1 : -1]), \
  (g_atomic_int_get) ((volatile gint G_GNUC_MAY_ALIAS *) (volatile void *) (atomic)))


The first line in there is essentially and expression version of G_STATIC_ASSERT().  So I suggest we add the following macro (and use it in gatomic.h too):

#define G_STATIC_ASSERT_EXPR(expr) ((void) sizeof (char[(expr) ? 1: -1]))
Comment 1 Matthias Clasen 2011-05-22 03:04:34 UTC

*** This bug has been marked as a duplicate of bug 626549 ***
Comment 2 Behdad Esfahbod 2011-05-22 17:10:55 UTC
Boy, I may have a bad memory, but I like my consistency :D