Thread (18 messages) 18 messages, 5 authors, 2024-06-13

Re: termios constants should be unsigned

From: Alejandro Colomar <alx@kernel.org>
Date: 2024-06-12 22:22:44
Also in: linux-man

Hi Elliott,

On Wed, Jun 12, 2024 at 05:54:43PM GMT, enh wrote:
quoted
BTW, that seems to be a bogus way to workaround this; the cast should
have been on the other side.  I'd say whoever maintains that code should
probably fix that to use unsigned types.
indeed. i've already sent out such a change :-)
quoted
 These constants are meant to
be 'tcflag_t', so a cast should be to that type, or the type of the
other side of the comparison, but casting to 'int' just for silencing a
waring seems nuts.
i suspect the reasoning was one of readability --- keeping the [short]
constants legible at the cost of making the expression slightly
longer.
quoted
This makes me wonder if breaking _those_ users could be a good thing...
like Paul Eggert said somewhere else today --- only if we're finding
real bugs. and so far we're not.

it's like the warn_unused_result argument. a purist would argue that
every function should have that annotation, because you should always
check for errors, and if you're not already doing so, your code is
already broken. whereas a pragmatist would argue that most people are
just going to add the "shut up, compiler" cast (or disable the warning
entirely) if their already-working code suddenly starts spamming
warnings next time they build it.

while my bar for that might not be as high as my bar for ABI breakage,
my source compatibility bar is still pretty high. it would be almost
unethical of me to make app developers do random busywork. i have to
be pretty confident (as with, say, "you just passed an fd > 1024 to an
fd_set function/macro and thus corrupted memory") that their code is
_definitely_ wrong. (and even there, that's going to have to be a
runtime check!)
Yeah, I can agree with that.  I'm that kind of pedantic purist for my
own code, and it's painful that historic accidents like this one don't
allow me to be so in my own code.  But I agree that fixing the entire
world when their code is braindamaged but works is asking too much.

I'll just disable that pedantic warning when I use termbits.  :)

Btw, thanks for fixing that brain-damaged cast.  ;-)

Have a lovely night!
Alex

-- 
<https://www.alejandro-colomar.es/>

Attachments

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help