[glib] glib-init: statically assert that int is exactly 32 bits long



commit be4fd3d0b0cc3c2aca204f2ee16ad88cf2d2f2be
Author: Simon McVittie <simon mcvittie collabora co uk>
Date:   Mon May 4 10:40:51 2015 +0100

    glib-init: statically assert that int is exactly 32 bits long
    
    The GVariant documentation says you can assume that types of no more
    than 32 bits may be assumed to be promoted to int by the usual
    promotions. If we're going to document that, we should statically
    assert that it's true, i.e. sizeof (int) >= sizeof (int32_t).
    
    All reasonable modern platforms are either ILP32 (32-bit platforms),
    LP64 (64-bit Linux, *BSD etc.), or LLP64 (64-bit Windows): there have
    been ILP64 platforms in the past, but ILP64 has the compelling
    disadvantage that {signed char, short, int} can't possibly provide
    all of {int8_t, int16_t, int32_t} unless int is 32 bits long.
    
    Bug: https://bugzilla.gnome.org/show_bug.cgi?id=730932
    Signed-off-by: Simon McVittie <simon mcvittie collabora co uk>
    Reviewed-by: Colin Walters

 glib/glib-init.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)
---
diff --git a/glib/glib-init.c b/glib/glib-init.c
index 07ca239..8923720 100644
--- a/glib/glib-init.c
+++ b/glib/glib-init.c
@@ -101,6 +101,13 @@ debug_key_matches (const gchar *key,
   return *key == '\0';
 }
 
+/* The GVariant documentation indirectly says that int is at least 32 bits
+ * (by saying that b, y, n, q, i, u, h are promoted to int). On any
+ * reasonable platform, int is in fact *exactly* 32 bits long, because
+ * otherwise, {signed char, short, int} wouldn't be sufficient to provide
+ * {int8_t, int16_t, int32_t}. */
+G_STATIC_ASSERT (sizeof (int) == sizeof (gint32));
+
 /**
  * g_parse_debug_string:
  * @string: (allow-none): a list of debug options separated by colons, spaces, or


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