<story><title>CryEngine out on GitHub</title><url>https://github.com/CRYTEK-CRYENGINE/CRYENGINE</url></story><parent_chain><item><author>NKCSS</author><text>This might be fun to look through; first thing I saw that I never thought of before was how to define flag enums.&lt;p&gt;From &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;github.com&amp;#x2F;CRYTEK-CRYENGINE&amp;#x2F;CRYENGINE&amp;#x2F;blob&amp;#x2F;release&amp;#x2F;Code&amp;#x2F;CryEngine&amp;#x2F;Cry3DEngine&amp;#x2F;BreakableGlassRenderNode.cpp&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;github.com&amp;#x2F;CRYTEK-CRYENGINE&amp;#x2F;CRYENGINE&amp;#x2F;blob&amp;#x2F;release&amp;#x2F;C...&lt;/a&gt;:&lt;p&gt;&lt;pre&gt;&lt;code&gt;    &amp;#x2F;&amp;#x2F; State flags
    enum EGlassRNState
    {
    	EGlassRNState_Initial     = 0,
    	EGlassRNState_Weakened    = 1 &amp;lt;&amp;lt; 0,
    	EGlassRNState_Shattering  = 1 &amp;lt;&amp;lt; 1,
    	EGlassRNState_Shattered   = 1 &amp;lt;&amp;lt; 2,
    	EGlassRNState_ActiveFrags = 1 &amp;lt;&amp;lt; 3
    };
&lt;/code&gt;&lt;/pre&gt;
Als a C# dev, I write Enum flags from time to time, but I always just write out the values; never thought of using bit-shifting to prevent typos :)</text></item></parent_chain><comment><author>Benjamin_Dobell</author><text>This is pretty standard practice, in C# too. However, it&amp;#x27;s still somewhat prone to typos.&lt;p&gt;If you don&amp;#x27;t care about backward compatibility (i.e. the flags are used internally and never written anywhere), then a better method is actually to grab the value one line above and bit shift it by one. That way you can insert values in the middle and you won&amp;#x27;t have to change every single line (just two).</text></comment>
<story><title>CryEngine out on GitHub</title><url>https://github.com/CRYTEK-CRYENGINE/CRYENGINE</url></story><parent_chain><item><author>NKCSS</author><text>This might be fun to look through; first thing I saw that I never thought of before was how to define flag enums.&lt;p&gt;From &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;github.com&amp;#x2F;CRYTEK-CRYENGINE&amp;#x2F;CRYENGINE&amp;#x2F;blob&amp;#x2F;release&amp;#x2F;Code&amp;#x2F;CryEngine&amp;#x2F;Cry3DEngine&amp;#x2F;BreakableGlassRenderNode.cpp&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;github.com&amp;#x2F;CRYTEK-CRYENGINE&amp;#x2F;CRYENGINE&amp;#x2F;blob&amp;#x2F;release&amp;#x2F;C...&lt;/a&gt;:&lt;p&gt;&lt;pre&gt;&lt;code&gt;    &amp;#x2F;&amp;#x2F; State flags
    enum EGlassRNState
    {
    	EGlassRNState_Initial     = 0,
    	EGlassRNState_Weakened    = 1 &amp;lt;&amp;lt; 0,
    	EGlassRNState_Shattering  = 1 &amp;lt;&amp;lt; 1,
    	EGlassRNState_Shattered   = 1 &amp;lt;&amp;lt; 2,
    	EGlassRNState_ActiveFrags = 1 &amp;lt;&amp;lt; 3
    };
&lt;/code&gt;&lt;/pre&gt;
Als a C# dev, I write Enum flags from time to time, but I always just write out the values; never thought of using bit-shifting to prevent typos :)</text></item></parent_chain><comment><author>cjbprime</author><text>The Linux kernel takes it a step farther:&lt;p&gt;#define BIT(nr)			(1UL &amp;lt;&amp;lt; (nr))&lt;p&gt;#define BIT_MASK(nr)		(1UL &amp;lt;&amp;lt; ((nr) % BITS_PER_LONG))&lt;p&gt;#define BIT_WORD(nr)		((nr) &amp;#x2F; BITS_PER_LONG)&lt;p&gt;#define BITS_TO_TYPE(nr, t)	(((nr)+(t)-1)&amp;#x2F;(t))</text></comment>