3 ms·
There's a very big C inherited footgun you can avoid with signed sizes: implicit conversions to unsigned on comparison.
by tpolzer 8y ago
There's a very big C inherited footgun you can avoid with signed sizes: implicit conversions to unsigned on comparison.
- loeg 8y agoGCC has had -Wsign-compare: -Wsign-compare Warn when a comparison between signed and unsigned values could produce an incorrect result when the signed value is converted to unsigned. In C++, this warning is also enabled by -Wall. In C, it is also enabled by -Wextra. Since 1996. https://github.com/gcc-mirror/gcc/commit/de9554eb8ae74764555178fc8bdf04cad9f3aa82 https://github.com/gcc-mirror/gcc/commit/de9554eb8ae74764555... (And prior to that explicit option, it was just enabled as part of -Wextra/-W, from 1995: https://github.com/gcc-mirror/gcc/commit/7030c69607d547b3227ad0aa3842bf7864c690f3 https://github.com/gcc-mirror/gcc/commit/7030c69607d547b3227... . For comparison, Google was founded in 1996.) I buy that some of the integer promotion rules really suck, and Google's founders learned C prior to 1996. But the compiler has been able to warn us about this particular footgun for a long time.