<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Code Style on Impletaph</title><link>https://blogsite-91e549.gitlab.io/tags/code-style/</link><description>Recent content in Code Style on Impletaph</description><generator>Hugo</generator><language>en-us</language><copyright>&lt;a href="https://creativecommons.org/licenses/by-nc/4.0/" target="_blank" rel="noopener"&gt;CC BY-NC 4.0&lt;/a&gt;</copyright><lastBuildDate>Wed, 30 Sep 2026 00:00:00 +0000</lastBuildDate><atom:link href="https://blogsite-91e549.gitlab.io/tags/code-style/index.xml" rel="self" type="application/rss+xml"/><item><title>Feature complete and ergonomic enums in C</title><link>https://blogsite-91e549.gitlab.io/posts/2026/09/feature-complete-and-ergonomic-enums-in-c/</link><pubDate>Wed, 30 Sep 2026 00:00:00 +0000</pubDate><guid>https://blogsite-91e549.gitlab.io/posts/2026/09/feature-complete-and-ergonomic-enums-in-c/</guid><description>&lt;p&gt;C and C++ were known for some time has having particularly underfeatured enumerations.
Given the follow very temporary &lt;a href="https://en.wikipedia.org/wiki/Enumerated_type"&gt;definition&lt;/a&gt; which will immediately breakdown when c so much as looks at it,&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;An &lt;strong&gt;ENUM&lt;/strong&gt;: A set of discrete named values, and a type who&amp;rsquo;s stored value can be exactly one of those from the associated set.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;It would &lt;em&gt;also&lt;/em&gt; be nice for an &lt;code&gt;enum&lt;/code&gt; type to be:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Printable&lt;/strong&gt;: We can trivially get a printable string from any value of the enum.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Iterable&lt;/strong&gt;: We can iterate through the values in the set represented by the enum.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Indexable&lt;/strong&gt;: If there&amp;rsquo;s data associated with the various enum values, we can use the enum to refer to, or look up, the piece of data associated with one of it&amp;rsquo;s values.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Closed&lt;/strong&gt;: We have some sort of facilities or language features to prevent values of enum type from being assigned arbitrary numeric values that have no meaning in the enum.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Usable as Sentinel&lt;/strong&gt;: A value of enum type can be used to indicate which procedure or data should be used.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;But wait! We can&amp;rsquo;t begin talking about sentinels without addressing the ginormous &amp;hellip;&lt;/p&gt;</description></item></channel></rss>