[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Cvs-cvs] ccvs/src ChangeLog admin.c

From: Larry Jones
Subject: Re: [Cvs-cvs] ccvs/src ChangeLog admin.c
Date: Tue, 13 Jun 2006 17:55:17 -0400 (EDT)

Derek R. Price writes:
> How do you reconcile that with all the library functions (e.g. getenv,
> strcpy, ...) that take and return signed char * arguments?

They don't take signed char arguments, they take "plain" char arguments,
which can be either signed or unsigned depending on the implementation. 
And the C Standard requires all of those routines to treat their
arguments as unsigned chars internally (on systems where it makes a
difference).  The reason for the "wrong" argument types is history:
that's the way they've always been defined and it would break a lot of
code to change them.  The Standard does require that "normal" characters
be non-negative when stored in a char, but as people use larger
character sets, it's no longer safe to count on people only using
"normal" characters.  The is*() functions all take int arguments, where
the argument must be between 0 and UCHAR_MAX, or EOF.  Passing any other
value (i.e., negative values other than whatever character just happens
to map to EOF) results in undefined behavior.

Unfortunately, that leaves us in a bit of a pickle:  Changing all of the
chars to unsigned char as I originally suggested causes problems using
the string functions, leaving them as chars causes problems when using
the ctype functions.  You're damned if you do and damned if you don't. 
On further reflection, the ctype functions are probably used less often
than the string functions, so changing all the types in probably not a
good idea after all.  That means that casts are required "near" the
ctype functions, exactly where is a matter of judgement.

-Larry Jones

I can feel my brain beginning to atrophy already. -- Calvin

reply via email to

[Prev in Thread] Current Thread [Next in Thread]