[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Correct arguments to isspace/isalnum
From: |
Ralf Wildenhues |
Subject: |
Re: Correct arguments to isspace/isalnum |
Date: |
Tue, 5 Oct 2004 08:39:26 +0200 |
User-agent: |
Mutt/1.4.1i |
* Bob Friesenhahn wrote on Mon, Sep 27, 2004 at 09:18:08PM CEST:
> On Mon, 27 Sep 2004, Ralf Wildenhues wrote:
> >* Bob Friesenhahn wrote on Mon, Sep 27, 2004 at 08:32:31PM CEST:
> >>On Mon, 27 Sep 2004, Ralf Wildenhues wrote:
> >>
> >>>Most systems accept this error, because it's so widespread.
> >>>No excuse stating that sign conversion is difficult in C ;)
> >>
> >>It seems that the correct answer to this depends on which standard you
> >>are conforming to and whether you are using C or C++. In C '89 these
> >>functions accept an 'int'. Naturally C++ has made things more
> >>correct.
> >
> >No. It's independent of the standard, except that I forgot C++
> >compatibility, sorry. At least in C the cast to unsigned char is
> >required, because in C these functions accept ranges within unsigned
> >char only. So for C++ we need to add another cast. Sigh.
>
> I don't think that libltdl needs to compile using C++ (I don't know of
> any such requirement). What I meant was that C++ is much more
> concise/correct than C regarding characters passed to/from functions.
> The C '89 language uses `int' while C++ uses `char'.
Yes, but: the C++ standard is supposed to be aligned with C89.
> So my system uses the prototypes:
>
> int isalnum(int c);
> int isspace(int c);
..which means, that not only your system uses this, but every system
that adheres to C89. And every system adhering to C++98 uses
corresponding
extern "C" int isalnum(int);
or compatible prototypes. Other than that, C++ is to be treated as a
different language as C. Character handling is different, not more
correct or less.
> >No. This issue was discovered by reading the code alone. If you think
> >my change is wrong, I would like backing from some standard which tells
> >me so. I know the original code can fail on some systems when given
> >characters with the 8th bit set, whereas the corrected does not.
> >
> >OK, updated patch below. Does this fix the warnings?
>
> I didn't mean to imply that there were new warnings. Libltdl already
> produces gobs of warnings. It was just that the cast was to a type
> other than what the function prototypes specify.
Yes, but the C standard specifies conversion from unsigned char to int:
C99, 6.3#2 says explicitly:
| The following may be used in an expression wherever an int or unsigned
| int may be used:
| - An object or expression with an integer type whose integer
| conversion rank is less than the rank of int and unsigned int.
So since there is no reason for casting to int (not even prevention of
warnings, as you mentioned), I am reverting this patch.
Regards,
Ralf
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: Correct arguments to isspace/isalnum,
Ralf Wildenhues <=