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
This commit is contained in:
Simon McVittie 2015-05-04 10:40:51 +01:00
parent 5227630077
commit be4fd3d0b0

View File

@ -101,6 +101,13 @@ debug_key_matches (const gchar *key,
return *key == '\0'; 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: * g_parse_debug_string:
* @string: (allow-none): a list of debug options separated by colons, spaces, or * @string: (allow-none): a list of debug options separated by colons, spaces, or