Current-Users archive

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

Re: Casting ctype lookups



On Mon, Nov 12, 2012 at 02:50:51PM -0500, Greg Troxel wrote:
> 
> Joerg Sonnenberger <joerg%britannica.bec.de@localhost> writes:
> 
> > On Mon, Nov 12, 2012 at 01:47:59PM -0500, D'Arcy J.M. Cain wrote:
> >> Should the inline macro cast the args for these table lookups?  I would
> >> like to modify sys/ctype_inline.h to change lookup lines like;
> >
> > No. Please read ctype(3).
> 
> I see the point about code that passes a signed char being incorrect.
> However, the standard seems to say that isalpha etc. are required to be
> functions that take an int, and may also be macros.  So it seems that
> code that is written with an unsigned char should compile without
> warnings.

Passing an 'unsigned char' is fine, and not warned about.
I suspect that the gcc warning is there specifically for the ctype
functions.

> Here's a simpler question: if these were implemented as functions, with
> the type signature required by the standard, how would that be different
> than adding a cast to int as D'Arcy suggests?

It isn't, and the code would break the same way - either with a SIGSEGV
or an incorrect answer.

> This all seems quite difficult; the notion of a int carrying either a
> char or EOF makes it likely to have errors from type promotion.

You'll find that is the standard return value from getc() etc.

I did a trawl a few years ago through all of $SRC looking for code
that might call isxxx() with a signed char value - found and fixed
plenty, but didn't find a single piece of code that could pass EOF.

        David

-- 
David Laight: david%l8s.co.uk@localhost


Home | Main Index | Thread Index | Old Index