NetBSD-Users archive

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

Re: toupper and warnings



On 2021-05-06 09:33, Martin Husemann wrote:
On Thu, May 06, 2021 at 09:26:33AM +0200, Johnny Billquist wrote:
I'm not sure I understand why you'd get a warning in the first place.
toupper should take an int as input. Which is signed.
If you pass in a char, it should always fit and work.
Why should you get a warning?

Because the function requires an unsigned char or EOF and is undefined
for everything else.

See CAVEATS in ctype(3).

Right. But is gcc really smart enough to understand at compile time if something else than -1 is the negative value, and that toupper in fact is more limited than what the signature says?

The *signature* of the function is int toupper(int). If you pass a char to that, I can't see that there would ever be a warning about any problems.

The fact that toupper in fact is only defined for -1..255 is hardly visible in the signature of the function.

  Johnny

--
Johnny Billquist                  || "I'm on a bus
                                  ||  on a psychedelic trip
email: bqt%softjar.se@localhost             ||  Reading murder books
pdp is alive!                     ||  tryin' to stay hip" - B. Idol


Home | Main Index | Thread Index | Old Index