<p></p>
<p dir="auto"><a class="user-mention" data-hovercard-type="user" data-hovercard-url="/users/kugel-/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/kugel-">@kugel-</a></p>
<p dir="auto">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.</p>
<p dir="auto">I'm probably doing this wrong...  I tried adding the following union to <code>stash.h</code>:</p>
<div class="highlight highlight-source-c"><pre><span class="pl-k">typedef</span> <span class="pl-k">union</span>
{
        gboolean b;
        gint n;
        gdouble d;
        gchar *s;
        gchar **v;
        <span class="pl-k">const</span> gchar *cs;
        <span class="pl-k">const</span> gchar **cv;
} StashPrefType;</pre></div>
<p dir="auto">The StashPref struct becomes:</p>
<div class="highlight highlight-source-c"><pre><span class="pl-k">struct</span> StashPref
{
        <span class="pl-c"><span class="pl-c">/*</span> ... <span class="pl-c">*/</span></span>
        StashPrefType *setting;
        StashPrefType default_value;
        <span class="pl-c"><span class="pl-c">/*</span> ... <span class="pl-c">*/</span></span>
};</pre></div>
<p dir="auto">Some functions need to be redefined:</p>
<div class="highlight highlight-source-c"><pre><span class="pl-en">add_pref</span>(StashGroup *group, GType type, StashPrefType *setting,
                <span class="pl-k">const</span> gchar *key_name, StashPrefType default_value);

<span class="pl-k">static</span> StashPref *
<span class="pl-en">add_widget_pref</span>(StashGroup *group, GType setting_type, StashPrefType *setting,
                <span class="pl-k">const</span> gchar *key_name, StashPrefType default_value,
                GType widget_type, StashWidgetID widget_id);

<span class="pl-k">void</span> <span class="pl-en">stash_group_add_widget_property</span>(StashGroup *group, StashPrefType *setting,
                <span class="pl-k">const</span> gchar *key_name, StashPrefType default_value, StashWidgetID widget_id,
                <span class="pl-k">const</span> gchar *property_name, GType type);</pre></div>
<p dir="auto">To use StashPrefType requires something like:</p>
<div class="highlight highlight-source-c"><pre><span class="pl-k">int</span> *setting = &se->setting->n;
<span class="pl-k">double</span> *setting = &se->setting->d;</pre></div>
<p dir="auto">Then calls to the above functions need to have casts to <code>StashPrefType</code>, like:</p>
<div class="highlight highlight-source-c"><pre><span class="pl-en">add_pref</span>(group, G_TYPE_BOOLEAN, (StashPrefType *) setting, key_name, (StashPrefType)default_value);</pre></div>
<p dir="auto">And any external uses of <code>stash_group_add_widget_property()</code> (<code>sidebar.c</code> and maybe plugins) also need to cast StashPrefType.</p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/geany/geany/pull/3004#issuecomment-971255719">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AAIOWJZPRLOLJFWNV3VOBSTUMNFDPANCNFSM5ICQ4AGQ">unsubscribe</a>.<br />Triage notifications on the go with GitHub Mobile for <a href="https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675">iOS</a> or <a href="https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub">Android</a>.
<img src="https://github.com/notifications/beacon/AAIOWJ7QNNCUTHOB3ICRCJTUMNFDPA5CNFSM5ICQ4AG2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOHHSC7JY.gif" height="1" width="1" alt="" /></p>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/geany/geany/pull/3004#issuecomment-971255719",
"url": "https://github.com/geany/geany/pull/3004#issuecomment-971255719",
"name": "View Pull Request"
},
"description": "View this Pull Request on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>