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.
This commit is contained in:
Ryan Lortie 2010-11-11 21:47:13 -05:00
parent 6bc20651ec
commit 48ca3add14
2 changed files with 7 additions and 1 deletions

View File

@ -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 <literal>typedef</literal> is valid.
</para>
<note><para>
A <literal>typedef</literal> is generally allowed in exactly the same
places that a variable declaration is allowed. For this reason, you should not use <literal>G_STATIC_ASSERT</literal> in the middle of blocks of code.
</para></note>
<para>
The macro should only be used once per source code line.
</para>

View File

@ -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);
}