Search code examples
cfunctionctype

In C, how possibly can an (implementation-defined?) character parameter be true for both islower() and isupper()? Book says so


The following two lines, about islower() and isupper(), are given in the same paragraph in the C book by Mike Banahan (Link: Section 9.3):

islower(int c)

True if c is a lower case alphabetic letter. Also true for an implementation defined set of characters which do not return true results from any of iscntrl, isdigit, ispunct or isspace. In the C locale, this extra set of characters is empty.

isupper(int c)

True if c is an upper case alphabetic character. Also true for an implementation-defined set of characters which do not return true results from any of iscntrl, isdigit, ispunct or isspace. In the C locale, this extra set of characters is empty.

Can you explain how can a character, if it doesn't return true results from any of iscntrl, isdigit, ispunct or isspace, result in true outcome for both the functions? As far as I know, a character can either be lowercase, or uppercase, not both (Assuming we are talking of character sets that have such a distinction...most European languages do).


Solution

  • The quotes from the book do not claim that isupper and islower will necessary return true simultaneously for the same symbol. They only say that if some other locale than C ,locale is used then there can be some additional symbols for which either isupper or islower (or both) can return true.

    Take into account that the C Standard defines isalpha in terms of isupper and islower

    The isalpha function tests for any character for which isupper or islower is true,

    Though it seems possible that ths same locale-specific symbol can be considered as upper and lower simultaneously. That is all four combinations are possible. For example

    isupper: false, islower: false
    isupper: true, islower: false
    isupper: false, islower: true
    isupper: true, islower: true
    

    The C Standard has a footnote:

    200) The functions islower and isupper test true or false separately for each of these additional characters; all four combinations are possible