Paul Eggert wrote:
> > $ gcc -Wall -S foo.c
> > foo.c:1: warning: integer constant is too large for ‘long’ type
> 
> I don't see how that would produce incorrect code for byteswap.h.

Indeed, gcc 4.4.7 warns but produces a long long value (no truncation).

> The longer story is C89 lacked 'long long'. Also, in C89 on a 32-bit int 
> platform the decimal integer literal 2147483648 had type 'unsigned int' 
> because 2147483648 fits in 'unsigned int' but not plain 'int'. Although 
> this misfeature was fixed in C99 it was present in many compilers for 
> some time after that. (It still seems to be present in MS Visual Studio! 
> See 
> <https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-2-c4146?view=msvc-170>.)
> 
> To help write portable code, GCC formerly warned about integer constants 
> that might not be portable to C89, but it then went ahead and produced 
> correct code.

Thanks for explaining. I remember that at least in the preprocessor,
truncation did occur. I don't remember when in the object code the
compilers (other than MSVC) stopped doing the truncation.

> The need for these warnings went away long ago (except perhaps for 
> Microsoft...) but they can be annoying so I installed the attached patch 
> to pacify older GCCs.

Thanks!

Bruno




Reply via email to