X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f Date: Sat, 25 Dec 2004 11:42:40 -0500 Message-Id: <200412251642.iBPGge9n026679@envy.delorie.com> From: DJ Delorie To: djgpp AT delorie DOT com In-reply-to: (message from Joe Wright on Sat, 25 Dec 2004 06:57:44 -0500) Subject: Re: CTYPE stuff for Eli or DJ References: <200412241848 DOT iBOImiRM013524 AT envy DOT delorie DOT com> <200412241919 DOT iBOJJnq5014101 AT envy DOT delorie DOT com> <01c4ea6a$Blat.v2.2.2$88d35240 AT zahav DOT net DOT il> Errors-To: nobody AT delorie DOT com X-Mailing-List: djgpp AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk > 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.