[PATCH] Suppress sign-conversion warning from FD_SET
Paul Eggert
eggert@cs.ucla.edu
Fri May 25 21:35:00 GMT 2012
On 05/25/2012 09:27 AM, Paul Pluzhnikov wrote:
> - ({ unsigned long int __d = (d); \
> + ({ unsigned long int __d = (unsigned long int) (d); \
As a general rule I'd rather avoid unnecessary casts.
The patch does not fix a bug, as the implicit conversion from
D's type 'int' to 'unsigned long int' has well-defined
behavior. And the patch may mask a later bug if someone
mistakenly invokes the macro with D being a pointer.
Instead, how about using 'long int', since that's guaranteed
to work without munging the sign? Something like this:
#define __FD_ELT(d) \
__extension__ \
({ long int __d = (d); \
(__builtin_constant_p (__d) \
? (0 <= __d && __d < __FD_SETSIZE \
? __d / __NFDBITS : __fdelt_warn (__d)) \
: __fdelt_chk (__d)); })
with a similar change to fdelt_chk's implementation, and
with the signatures of __fdelt_warn and __fdelt_chk
changed to use 'long int' rather than 'unsigned long int'.
The generated code should be identical.
More information about the Libc-alpha
mailing list