The book The C Programming Language by Kernighan and Ritchie, second edition states on page 43 in the chapter about Type Conversions:
Another example of
chartointconversion is the functionlower, which maps a single character to lower case for the ASCII character set. If the character is not an upper case letter,lowerreturns returns it unchanged./* lower: convert c to lower case; ASCII only */ int lower(int c) { if (c >= 'A' && c <= 'Z') return c + 'a' - 'A'; else return c; }
It isn't mentioned explicitly in the text so I'd like to make sure I understand it correctly: The conversion happens when you call the lower function with a variable of type char, doesn't it? Especially, the expression
c >= 'A'
has nothing to do with a conversion from int to char since a character constant like 'A'
is handled as an int internally from the start, isn't it? Edit: Or is this different (e.g. a character constant being treated as a char) for ANSI C, which the book covers?