The code I'm compiling (not written by me) has a macro for checking a version number and then doing something if the version falls within the specified limits:
#define VER(file_version, first_version, last_version, block)\ if ((((Uint16)file_version) >= ((Uint16)first_version)) && (((Uint16)file_version) <= ((Uint16)last_version)))\ {\ block;\ }
The file_version passed in is an Uint8 and in some cases where this macro is used there is no upper limit for it so last_version is specified as 0xff so that the "file_version <= last_version" comparison will always be true. This is not a bug and is the wanted behavior but unfortunately gcc with -Wall refuses to shut up about it (I also use -Werror because I don't want to miss any warnings that might be bugs).
ppc-amigaos-gcc -std=gnu99 --no-strict-aliasing -O2 -Wall -Werror -I. -I/SDK/local/common/include/SDL -c -o snd/music.o snd/music.c
cc1: warnings being treated as errors
snd/music.c: In function 'load_wavetable_entry':
snd/music.c:1525: warning: comparison is always true due to limited range of data type
snd/music.c:1526: warning: comparison is always true due to limited range of data type
snd/music.c:1527: warning: comparison is always true due to limited range of data type
snd/music.c:1528: warning: comparison is always true due to limited range of data type
snd/music.c:1529: warning: comparison is always true due to limited range of data type
--- snip ---
Obviously the author of the code has tried to get around this warning by casting both values to Uint16 before doing this comparison but it seems that gcc 4.2.4 is "smart" enough to see through this ruse. I've tried adding "-Wno-type-limits" to stop this nonesense but unfortunately it is only supported in gcc >= 4.3 while the SDK gcc is version 4.2.4.
So does anyone know of an easy way to get around this apart from removing -Wall or -Werror options? Changing every invocation of the VER() macro in the code is not an option...
Well I got around the problem by defining a static inline function for doing the comparison and then using it inside the VER() macro like so:
Now I just wonder at which version gcc will be "smart" enough to see through this workaround...
@salass00
Clobbered this one together:
and compiled with this:
No more compile errors.
Output:
OldFart