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 13:06, Greg Troxel wrote:

Johnny Billquist <bqt%update.uu.se@localhost> writes:

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 signature is that it takes an int, but the specification is that if
the value of the int is other than EOF or something representable as
unsigned char (projecting to he implementation, meaning -1 is ok and
0..255 is ok), then you get UB.

Right. My question is just how on earth gcc would know this? There is nothing in the actual declaration that tells (or even can) tell this. So this would then (again) be an example of gcc knowing more about the function than is actually visible. What if I wrote my own function called toupper, which was defined for the full range of an int? Would gcc then understand that this is a different toupper that it shouldn't warn about?

  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