Add examples for G_STRINGIFY and G_PASTE
authorWill Thompson <will.thompson@collabora.co.uk>
Thu, 3 Jun 2010 13:50:19 +0000 (14:50 +0100)
committerWill Thompson <will.thompson@collabora.co.uk>
Sun, 6 Jun 2010 16:49:56 +0000 (17:49 +0100)
docs/reference/glib/tmpl/macros_misc.sgml

index 2396e5d..b8f229d 100644 (file)
@@ -100,18 +100,49 @@ does not include <function>string.h</function> for you.
 <!-- ##### MACRO G_STRINGIFY ##### -->
 <para>
 Accepts a macro or a string and converts it into a string after
-preprocessor argument expansion.
+preprocessor argument expansion. For example, the following code:
 </para>
 
+<informalexample><programlisting>
+#define AGE 27
+const gchar *greeting = G_STRINGIFY (AGE) " today!";
+</programlisting></informalexample>
+
+<para>
+is transformed by the preprocessor into (code equivalent to):
+</para>
+
+<informalexample><programlisting>
+const gchar *greeting = "27 today!";
+</programlisting></informalexample>
+
 @macro_or_string: a macro or a string.
 
 
 <!-- ##### MACRO G_PASTE ##### -->
 <para>
-Yields a new preprocessor pasted identifier 'identifier1identifier2'
-from its expanded arguments 'identifier1' and 'identifier2'.
+Yields a new preprocessor pasted identifier <code>identifier1identifier2</code>
+from its expanded arguments @identifier1 and @identifier2. For example, the
+following code:
 </para>
 
+<informalexample><programlisting>
+#define GET(traveller,method) G_PASTE(traveller_get_, method) (traveller)
+const gchar *name = GET (traveller, name);
+const gchar *quest = GET (traveller, quest);
+GdkColor *favourite = GET (traveller, favourite_colour);
+</programlisting></informalexample>
+
+<para>
+is transformed by the preprocessor into:
+</para>
+
+<informalexample><programlisting>
+const gchar *name = traveller_get_name (traveller);
+const gchar *quest = traveller_get_quest (traveller);
+GdkColor *favourite = traveller_get_favourite_colour (traveller);
+</programlisting></informalexample>
+
 @identifier1: an identifier
 @identifier2: an identifier
 @Since: 2.20