From 3c14b6846d5ea9fb2b4e07fc0a8c4587d9fc2b68 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Fri, 20 May 2022 12:56:03 +0100 Subject: [PATCH] docs: Standardise property ID enums in examples MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Drop the redundant `PROP_0` (which isn’t a real property) and initialise the first member of the enum instead. Add a typedef so that the enum type can be used in `switch` statements in `get_property()` and `set_property()` vfuncs. This allows `-Wswitch-enum` to be used to improve type safety. The examples here don’t have `get_property()` or `set_property()` vfuncs, but people might copy/paste the code to somewhere which does. Signed-off-by: Philip Withnall --- gobject/gobject.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/gobject/gobject.c b/gobject/gobject.c index caee34f4e..a7a1d3032 100644 --- a/gobject/gobject.c +++ b/gobject/gobject.c @@ -707,9 +707,11 @@ g_object_class_install_property (GObjectClass *class, * class initialization: * * |[ - * enum { - * PROP_0, PROP_FOO, PROP_BAR, N_PROPERTIES - * }; + * typedef enum { + * PROP_FOO = 1, + * PROP_BAR, + * N_PROPERTIES + * } MyObjectProperty; * * static GParamSpec *obj_properties[N_PROPERTIES] = { NULL, }; * @@ -732,7 +734,7 @@ g_object_class_install_property (GObjectClass *class, * gobject_class->set_property = my_object_set_property; * gobject_class->get_property = my_object_get_property; * g_object_class_install_properties (gobject_class, - * N_PROPERTIES, + * G_N_ELEMENTS (obj_properties), * obj_properties); * } * ]| @@ -1406,12 +1408,11 @@ g_object_notify (GObject *object, * g_object_class_install_property() inside a static array, e.g.: * *|[ - * enum + * typedef enum * { - * PROP_0, - * PROP_FOO, + * PROP_FOO = 1, * PROP_LAST - * }; + * } MyObjectProperty; * * static GParamSpec *properties[PROP_LAST]; *