alexfru / SmallerC

Simple C compiler
BSD 2-Clause "Simplified" License
1.35k stars 155 forks source link

Fix compiler warning with clang #4

Closed jezze closed 9 years ago

jezze commented 9 years ago

I just ran the gcc command in the wiki but replaced it with clang.

Apparently doing && with a define is not ok.

alexfru commented 9 years ago

What was the exact warning? I don't see anything wrong here.

jezze commented 9 years ago

$ clang -v clang version 3.4.2 (tags/RELEASE_34/dot2-final) Target: x86_64-unknown-linux-gnu

$ clang -Wall -Wextra -O2 smlrc.c -o smlrc smlrc.c:1325:29: warning: use of logical '&&' with constant operand [-Wconstant-logical-operand] c -= (c >= 0x80 && CHAR_MIN) * 0x100; ^ ~~~~ smlrc.c:1325:29: note: use '&' for a bitwise operation c -= (c >= 0x80 && CHAR_MIN) * 0x100; ^~ & smlrc.c:1325:29: note: remove constant to silence this warning c -= (c >= 0x80 && CHAR_MIN) * 0x100; ~^~~ smlrc.c:1344:29: warning: use of logical '&&' with constant operand [-Wconstant-logical-operand] c -= (c >= 0x80 && CHAR_MIN) * 0x100; ^ ~~~~ smlrc.c:1344:29: note: use '&' for a bitwise operation c -= (c >= 0x80 && CHAR_MIN) * 0x100; ^~ & smlrc.c:1344:29: note: remove constant to silence this warning c -= (c >= 0x80 && CHAR_MIN) * 0x100; ~^~~ 2 warnings generated.

jezze commented 9 years ago

That didnt out to well... the arrows are suppose to point at the first & in &&

alexfru commented 9 years ago

Strictly speaking, CHAR_MIN < 0 is also a constant and a newer version of the compiler or a different compiler can still issue a warning here. If you really want to fix it, a different solution is needed. I'd like to avoid non-portable solutions and solutions relying on features not supported by Smaller C itself. Likewise, #if(n)def's should probably avoided as well for simple things like this. Suggestions?

alexfru commented 9 years ago

I'm accepting it as a temporary solution.