|
|
Message-ID: <20250606025613.GJ1827@brightrain.aerifal.cx> Date: Thu, 5 Jun 2025 22:56:13 -0400 From: Rich Felker <dalias@...c.org> To: Andy Caldwell <andy.m.caldwell@...glemail.com> Cc: musl@...ts.openwall.com, David Steele <david@...ackrest.org>, noloader@...il.com Subject: Re: Sign conversion warning in FD_ISSET() On Fri, Jun 06, 2025 at 01:34:53AM +0100, Andy Caldwell wrote: > On Fri, Jun 6, 2025 at 1:29 AM Nick Wellnhofer <wellnhofer@...um.de> wrote: > > > > On Jun 6, 2025, at 02:23, Andy Caldwell <andy.m.caldwell@...glemail.com> wrote: > > > > > >>> There probably is some way to get it right with clever use of the > > >>> ternary operator but I haven't come up with anything in the first few > > >>> seconds thinking about it. > > >>> > > >>> Rich > > > > > > Yes, the ternary operator can be used to create a C89-compatible > > > version (this allows anything coercible to an `int` or an `unsigned`, > > > so it mostly only refuses pointers and structures). > > > > > > #define SOCKET_TO_UNSIGNED(s) ((unsigned)(1?(s):0)) > > > > This doesn't work with pointers because 0 is a null pointer constant. But if you change the value to 1, it should work. > > > > Nick > > > > Thanks Nick and Rich, you are both correct, I originally had it as > `0?1:(s)` then changed it (without re-testing) for the email, like a > fool. However in re-testing I notice that this only triggers a > warning `-Wint-conversion` rather than an error when passed a pointer > in C89 mode (it gives an error when passed a structure in any mode). Something like ((unsigned)(1?1*(s):0)) ? Rich
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.