bug-gnulib
[Top][All Lists]
Advanced

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

Re: [PATCH] byteswap: port better to limited platforms


From: Paul Eggert
Subject: Re: [PATCH] byteswap: port better to limited platforms
Date: Sat, 18 May 2024 09:05:53 -0700
User-agent: Mozilla Thunderbird

On 2024-05-17 16:51, Bruno Haible wrote:
-------------------------- foo.c --------------------------
unsigned long long x = 0xff00000000000000;
-----------------------------------------------------------

$ 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.

If memory serves, GCC formerly warned about integer constants that had a "surprising" type, for a definition of "surprising" that was too generous so that there were too many false alarms.

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.

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.


PS. We could simplify the code by removing all uses of __builtin_bswap64 etc. Although these uses are present only to improve performance, they do not improve performance with GCC 14 x86-64 with -O2.

Attachment: 0001-byteswap-pacify-GCC-4.4.7-and-older.patch
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]