M
mr_semantics
I have been reading about the practise of casting values to unsigned
char while using the <ctype.h> functions. For example,
c = toupper ((unsigned char) c);
Now I understand that the standard says this about the <ctype.h>
functions:
"The header <ctype.h> declares several functions useful for classifying
and mapping characters.166) In all cases the argument is an int, the
value of which shall be representable as an unsigned char or shall
equal the value of the macro EOF. If the argument has any other value,
the behavior is undefined."
I am having a hard time formulating my question - basically its like
this though - Some people say cast to unsigned char (as in the above
example), whereas I have seen some people argue that casting to
unsigned char is unecessary, and if it is done, then a recast back to
int is necessary, because functions like toupper() expect an int, eg,
toupper( (int)((unsigned char) c) );
So what is the right thing to do? Cast to unsigned char? Cast to
unsigned char and back to int?
char while using the <ctype.h> functions. For example,
c = toupper ((unsigned char) c);
Now I understand that the standard says this about the <ctype.h>
functions:
"The header <ctype.h> declares several functions useful for classifying
and mapping characters.166) In all cases the argument is an int, the
value of which shall be representable as an unsigned char or shall
equal the value of the macro EOF. If the argument has any other value,
the behavior is undefined."
I am having a hard time formulating my question - basically its like
this though - Some people say cast to unsigned char (as in the above
example), whereas I have seen some people argue that casting to
unsigned char is unecessary, and if it is done, then a recast back to
int is necessary, because functions like toupper() expect an int, eg,
toupper( (int)((unsigned char) c) );
So what is the right thing to do? Cast to unsigned char? Cast to
unsigned char and back to int?