Compiler warnings for compile time constants in inactive branches

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi

What is the best way to get rid of warnings which GCC spuriously raises for inactive code branches, like in the following example?

const int c = 33;
int result =  (c < 32) ? (1 << c) : 0;
// previous line raises "left shift count >= width of type" warning

In Visual Studio I would just selectively deactivate the warnings around the affected code area.
Altenatively I could use an ugly fix like
int result =  (c < 32) ? (1 << c*(c < 32)) : 0;
or branch out the code in separate template specializations. Is there any better way to do this in GCC?

Regards,
  Stephan




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux