3 ms·
Thanks to apple we have a compiler alternative, that actually helps with this problem. alistra@bialobrewy ~ % clang -Weverything 1.c 1.c:6:8: warning: comp
by thealistra 15y ago
Thanks to apple we have a compiler alternative, that actually helps with this problem.
alistra@bialobrewy ~ % clang -Weverything 1.c
1.c:6:8: warning: comparison of integers of different signs: 'int' and 'unsigned int' [-Wsign-compare]
if(-1 < x)
~~ ^ ~
- noodly 15y agogcc also has -Wsign-compare option that warns about such comparisons.
- greyfade 15y agoGCC prints a similar warning with `-Wall`
- thealistra 15y agoactually with -Wextra alistra@bialobrewy ~ % gcc -Wextra 1.c 1.c: In function ‘main’: 1.c:6:8: warning: comparison between signed and unsigned integer expressions alistra@bialobrewy ~ % gcc -Wall 1.c alistra@bialobrewy ~ %
- _delirium 15y agoYes, for some reason in gcc, -Wall enables -Wsign-compare in C++ mode, but not in C mode. Maybe too much existing C code uses those kinds of comparisons?
- thealistra 15y agoThe fact the code uses those kinds of comparisons, doesn't mean, that it uses it properly.