Re: casting to unsigned char for is*() and to*() functions
- From: "James Daughtry" <mordock32@xxxxxxxxxxx>
- Date: 30 Jun 2005 06:46:03 -0700
> The reason you need the cast is that converting directly
> from plain `char' to `int' might not produce what toupper()
> needs.
Does the standard guarantee that casting signed char with a negative,
non-EOF value, to unsigned char will produce the expected character? It
seems to me that unless this guarantee is provided, the cast would give
you defined behavior but garbage results. That's only marginally better
than undefined behavior. As such, wouldn't it be better to simply avoid
the operation if the value is out of range?
if (c == EOF || (c >= 0 && c <= UCHAR_MAX))
c = toupper(c);
else {
/* Special treatment for c */
}
.
- Follow-Ups:
- Re: casting to unsigned char for is*() and to*() functions
- From: Lawrence Kirby
- Re: casting to unsigned char for is*() and to*() functions
- From: Eric Sosman
- Re: casting to unsigned char for is*() and to*() functions
- References:
- casting to unsigned char for is*() and to*() functions
- From: mr_semantics
- Re: casting to unsigned char for is*() and to*() functions
- From: Eric Sosman
- casting to unsigned char for is*() and to*() functions
- Prev by Date: Re: why use -> (not .) with pointers?
- Next by Date: Re: Floatin point issues
- Previous by thread: Re: casting to unsigned char for is*() and to*() functions
- Next by thread: Re: casting to unsigned char for is*() and to*() functions
- Index(es):
Relevant Pages
|