@kugel-

I don't understand the benefit of using union over casting the pointers. Based on what I'm reading online, they're both considered "bad". It also looks like switching to using unions may require changing existing code, which I've been trying to avoid.

I'm probably doing this wrong... I tried adding the following union to stash.h:

typedef union
{
	gboolean b;
	gint n;
	gdouble d;
	gchar *s;
	gchar **v;
	const gchar *cs;
	const gchar **cv;
} StashPrefType;

The StashPref struct becomes:

struct StashPref
{
	/* ... */
	StashPrefType *setting;
	StashPrefType default_value;
	/* ... */
};

Some functions need to be redefined:

add_pref(StashGroup *group, GType type, StashPrefType *setting,
		const gchar *key_name, StashPrefType default_value);

static StashPref *
add_widget_pref(StashGroup *group, GType setting_type, StashPrefType *setting,
		const gchar *key_name, StashPrefType default_value,
		GType widget_type, StashWidgetID widget_id);

void stash_group_add_widget_property(StashGroup *group, StashPrefType *setting,
		const gchar *key_name, StashPrefType default_value, StashWidgetID widget_id,
		const gchar *property_name, GType type);

To use StashPrefType requires something like:

int *setting = &se->setting->n;
double *setting = &se->setting->d;

Then calls to the above functions need to have casts to StashPrefType, like:

add_pref(group, G_TYPE_BOOLEAN, (StashPrefType *) setting, key_name, (StashPrefType)default_value);

And any external uses of stash_group_add_widget_property() (sidebar.c and maybe plugins) also need to cast StashPrefType.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.