From 48ca3add143896fa5664860a94947907cfe5daa2 Mon Sep 17 00:00:00 2001 From: Ryan Lortie Date: Thu, 11 Nov 2010 21:47:13 -0500 Subject: [PATCH] G_STATIC_ASSERT: clarify when use is valid Clarify when the use of G_STATIC_ASSERT is valid and fix up an invalid use of it in GDBus. --- docs/reference/glib/tmpl/macros_misc.sgml | 6 ++++++ gio/gdbusmessage.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/reference/glib/tmpl/macros_misc.sgml b/docs/reference/glib/tmpl/macros_misc.sgml index 387a8a5..eb875bb 100644 --- a/docs/reference/glib/tmpl/macros_misc.sgml +++ b/docs/reference/glib/tmpl/macros_misc.sgml @@ -153,6 +153,12 @@ GdkColor *favourite = traveller_get_favourite_colour (traveller); The G_STATIC_ASSERT macro lets the programmer check a condition at compile time, the condition needs to be compile time computable. The macro can be used in any place where a typedef is valid. + + +A typedef is generally allowed in exactly the same +places that a variable declaration is allowed. For this reason, you should not use G_STATIC_ASSERT in the middle of blocks of code. + + The macro should only be used once per source code line. diff --git a/gio/gdbusmessage.c b/gio/gdbusmessage.c index ade5e7b..92ee23a 100644 --- a/gio/gdbusmessage.c +++ b/gio/gdbusmessage.c @@ -1183,10 +1183,10 @@ parse_value_from_blob (GMemoryInputStream *mis, { guint64 v; gdouble *encoded; + G_STATIC_ASSERT (sizeof (gdouble) == sizeof (guint64)); v = g_data_input_stream_read_uint64 (dis, NULL, &local_error); if (local_error != NULL) goto fail; - G_STATIC_ASSERT (sizeof (gdouble) == sizeof (guint64)); encoded = (gdouble *) &v; ret = g_variant_new_double (*encoded); } -- 2.7.4