This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Compiler warnings for compile time constants in inactive branches
- From: Stephan Tolksdorf <andorxor at gmx dot de>
- To: gcc-help at gcc dot gnu dot org
- Date: Sat, 18 Nov 2006 16:55:24 +0100
- Subject: Compiler warnings for compile time constants in inactive branches
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