Current-Users archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: Casting ctype lookups
On Wed, 14 Nov 2012 15:05:01 +0200
Alan Barrett <apb%cequrux.com@localhost> wrote:
> On Wed, 14 Nov 2012, D'Arcy J.M. Cain wrote:
> >Would this be safer?
> >
> >#define toupper(c)\
> > ((int)((_toupper_tab_ + 1)[(int)(unsigned char)(c)]))
>
> No. That would break when the caller passes the int value EOF.
Right. Forgot about that.
> I believe that there's nothing wrong with NetBSD's definitions of
> these functions and macros. If the caller gets a warning about
> them, then there's a problem in the caller's code.
Functions yes but the macros don't work the same.
$ cat t.c
#include <stdio.h>
#include <ctype.h>
void func(char *s)
{
while (*s++) *s = toupper(*s);
}
int main(void)
{
char s[] = "Test string";
func(s);
printf("%s\n", s);
return 0;
}
$ gcc -Wall -Werror -o t t.c && ./t
cc1: warnings being treated as errors
t.c: In function 'func':
t.c:5:3: error: array subscript has type 'char'
$ gcc -Wall -Werror -D_CTYPE_NOINLINE -o t t.c && ./t
TEST STRING
With my proposed change the function and the macro both act the same.
--
D'Arcy J.M. Cain <darcy%NetBSD.org@localhost>
http://www.NetBSD.org/ IM:darcy%Vex.Net@localhost
Home |
Main Index |
Thread Index |
Old Index