<story><title>The Little C Function From Hell</title><url>http://blog.regehr.org/archives/482</url></story><parent_chain><item><author>raverbashing</author><text>A little C tip I learned from hard experience&lt;p&gt;NEVER, EVER, NOT IN A MILLION YEARS use a signed int/char etc, unless you are &lt;i&gt;200% certain&lt;/i&gt; you&apos;re doing the right thing (that is, it&apos;s for something specific you need it)&lt;p&gt;You WILL have problems, period.&lt;p&gt;&quot;Oh it&apos;s just a matter of knowing the C spec&quot; then please go ahead as I grab the popcorn.</text></item></parent_chain><comment><author>ajross</author><text>&quot;For something specific you need it&quot; meaning ... a negative number, like an array or memory address offset?  I mean, sure, I agree that you should be doing anything sensitive to 2&apos;s complement behavior on unsigned quantities.  And if you know the values are positive-definite, unsigned has much cleaner behavior.  And I&apos;d even entertain the argument that unsigned should have been the default in the language spec and that signed quantities are the ones that should have specially declared types.&lt;p&gt;But... your advice as written is just insane.  They are real, and required routinely.  You can&apos;t just apply this as a &quot;for dummies&quot; rule without essentially ruling out half of the code they&apos;ll need to write.</text></comment>
<story><title>The Little C Function From Hell</title><url>http://blog.regehr.org/archives/482</url></story><parent_chain><item><author>raverbashing</author><text>A little C tip I learned from hard experience&lt;p&gt;NEVER, EVER, NOT IN A MILLION YEARS use a signed int/char etc, unless you are &lt;i&gt;200% certain&lt;/i&gt; you&apos;re doing the right thing (that is, it&apos;s for something specific you need it)&lt;p&gt;You WILL have problems, period.&lt;p&gt;&quot;Oh it&apos;s just a matter of knowing the C spec&quot; then please go ahead as I grab the popcorn.</text></item></parent_chain><comment><author>Roboprog</author><text>There&apos;s a certain aspect of &quot;functions have domains, not just ranges&quot; at work here as well  --  e.g. - restricting the (math) tan() function to the domain of -90 to 90 degrees (exclusive), unless you really get off on watching it cycle over madness.  If you are going to be playing around the edges of something, it behooves you to put some kind of pre-condition in with an assert of similar mechanism.&lt;p&gt;In fairness, I guess a function like this is a good example of why you should put in preconditions, as well as a good demonstration that &quot;not all the world is a VAX&quot; (nor MS C 7, nor GCC version N)  :-)</text></comment>