tech-userlevel archive

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

Re: using the interfaces in ctype.h

>>>          .. if (isspace((unsigned char) buf[0])) ...
>>> won't work if isspace() is in-line and there's not enough casting
>>> in the macro.
>> I can't see how it could fail.  Could you give an example?
> It will fail by generating the warning which prevents compilation
> with -Werror on some machines.

Which warning is that?  I can't seem to find the thread-starting
message, and I certainly haven't gotten any warnings when using casts
to unsigned char (which presumably just means I'm not using whichever
-W option turns that warning on).

> (Apparently there are some compilers that complain about indexing
> using (unsigned chars) -- probably those machines on which char is
> identical to unsigned char, but I'm guessing.)

I'd consider such a warning broken, since indexing with unsigned char
is well-defined and safe.  Your mention of -Werror makes me think
you're talking about gcc, but "some compilers" makes me think you're
not.  If I had to build my code with a compiler that warned about that
and couldn't turn the warning off, I'd disable -Werror or its analog,
filter out the warning in my cc wrapper, and forget the issue.

>> warnings from some compiler versions about "array subscript has type
>> char", which let a coder catch such sloppy code; while this doesn't
>> apply to 3.1's compiler in my experience,
> It happens for 3.1 and gcc for x86.

Interesting.  It does for me too, when I try it now.

I wonder why I thought it didn't.

> I can't find a place where C99 requires that any implementation of a
> function-like macro for a library function be "warning-equivalent" to
> calling the library function.

I don't think there is any such requirement.  A compiler is required to
produce "at least one diagnostic" in some circumstances, but as far as
I know it is never required to *not* produce diagnostics.

> In other words, C99 does not require that isspace(x) be
> "warning-equivalent" to (isspace)(x).  But I happen to think that
> it's in the spirit of the specification for isspace(x), even though I
> agree that doing so may be inconvenient.

I believe that they should be semantically equivalent in terms of what
the generated code does.  I see no particular reason to go out of our
way to make them warning-equivalent, especially when that means
silencing a warning which helps catch misuses.

/~\ The ASCII                           der Mouse
\ / Ribbon Campaign
 X  Against HTML     
/ \ Email!           7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B

Home | Main Index | Thread Index | Old Index