tech-userlevel archive

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

Re: pkgsrc RC scripts

On Oct 19, 2009, at 6:50 AM, der Mouse wrote:

while (isspace((int)*value))
I'm missing why you would bother casting to (int) in the ctype macro
arg here.
Perhaps optional, but value is declared as char* and isspace() takes
an int.

Yes, but the _reason_ it takes an int is relevant: it needs to be able
to accept any value an unsigned char can take on, _plus EOF_.  In the
words of C99, "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".  The warning is calling out a case where the undefined
behaviour clause may occur - see my other mail in this thread.

Right, but if it were a real procedure, the explicit cast isn't needed, because that promotion is mandatory per the C language spec. In other words, putting in the cast would be for clarity, not correctness; the *defined* behavior is the same.

(Yes, C will always promote char to int in a procedure call, which is
why I said "perhaps optional".)

isspace() is not a procedure call in our implementation, at least not
when called as in the quote above.  This too is permitted: "Any
function declared in a header may be additionally implemented as a
function-like macro defined in the header".

Yes, and I'd forgotten that when I posted my note. File this one under "Why macros are not an adequate substitute for inline procedures".

I do wonder if our code should cast the argument explicitly before using it as an array subscript, since (as I noted) that would be done automatically were isspace() a real procedure.

                --Steve Bellovin,

Home | Main Index | Thread Index | Old Index