LWN.net Logo

Unsigned versus signed

Unsigned versus signed

Posted May 24, 2011 12:58 UTC (Tue) by cesarb (subscriber, #6266)
In reply to: Sure, but then you deserve what you get... by khim
Parent article: What Every C Programmer Should Know About Undefined Behavior #3/3

Wow...

That was an impressive one. I did not expect gcc to use *val* for the loop condition.

I think this is yet one more point in favor of a personal rule of "always use unsigned unless you have a good reason to use signed" (that is, use "unsigned" by default when programming). If you followed that rule, all three "int" on this function would become "unsigned int", since there is no good reason to use signed here.


(Log in to post comments)

Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds