Search code examples
cgtkglib

GLib:C: How do I print a GValue


How do I g_print a GValue, if I don't know it's type at compile time?

Is there some kind of special format character for the g_print format string?


Solution

  • Depends what format you want to print it in. If you don’t really care about the format, you can use g_value_transform() to convert the value into a second GValue which has been initialised with type G_TYPE_STRING.

    If you do care about the format, you will need to have a multi-branch if statement which compares the value of G_VALUE_TYPE() for your GValue against many different GTypes. In the body of each if block you’d have type-specific printing code.