tech-userlevel archive

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

Re: pkgsrc RC scripts



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

> (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".

/~\ The ASCII                             Mouse
\ / Ribbon Campaign
 X  Against HTML                mouse%rodents-montreal.org@localhost
/ \ Email!           7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B


Home | Main Index | Thread Index | Old Index