Skip to main content
1 of 2
Adam Haun
  • 22.3k
  • 4
  • 52
  • 94

An easy way to eliminate the warnings is to avoid using -Wconversion in GCC. I think you have to enable this option manually, but if not, you can use -Wno-conversion to disable it. You can enable warnings for sign and FP precision conversions via other options, if you still want those.

The -Wconversion warnings are almost always false positives, which is probably why not even -Wextra enables it by default. A Stack Overflow question has a lot of suggestions for good option sets. Based on my own experience, this is a good place to start:

-std=c99 -pedantic -Wall -Wextra -Wshadow

Add more if you need them, but odds are you won't.

If you must keep -Wconversion, you can shorten your code a bit by only typecasting the numeric operand:

value16 <<= (uint16_t)8;
value8 += (uint8_t)2;

That's not easy to read without syntax highlighting, though.

Adam Haun
  • 22.3k
  • 4
  • 52
  • 94