Mail Archives: djgpp/2004/12/25/11:43:25
> It's the right thing because the array itself has 257 elements of
> unsigned short, element 0 being 0. Elements 1..256 have bits set (or
> not) depending on the characteristics of characters 0..255, hence
> the +1 in the macro. Out-of-range should return 0. What you return?
The correct thing to return, when the program passes you an erroneous
input, is an error signal and set errno to ERANGE. Since the ctype
functions have no way of returning an error signal directly, the error
must be signalled indirectly. We do this by segfaulting. If you want
to handle the error, install a segfault handler.
But this should never happen, as you should not be passing such values
to the ctype functions.
We certainly should NOT be returning a successful value when passed
invalid inputs.
We do not want to help the programmer write bad code. We want bad
code to suffer as much as possible, to help them find the bad code and
fix it. That is the best way to help the programmer write good code.
- Raw text -