[ovs-discuss] [PATCH 1/2] Cleanup isdigit() warnings.

Ben Pfaff blp at nicira.com
Tue Aug 25 16:48:26 UTC 2009


Justin Pettit <jpettit at nicira.com> writes:

> NetBSD's gcc complains if isdigit()'s argument is not an integer.  This
> provides the appropriate cast.

What warning does it give?

At any rate, it doesn't make any sense to cast the argument of
isdigit to int, because that doesn't fix the problem that, I
imagine, the compiler is trying to point out: the argument to
isdigit() must be EOF or in the range 0...UCHAR_MAX.  If we need
a cast, a cast to 'unsigned char' is a better choice, because it
forces the argument into the correct range.

See C99 7.4 "Character handling <ctype.h>":

1    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.




More information about the discuss mailing list