Complete.Org: Mailing Lists: Archives: freeciv-dev: January 2001:
[Freeciv-Dev] Re: Compiler-warnings
Home

[Freeciv-Dev] Re: Compiler-warnings

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: Tony Stuckey <stuckey@xxxxxxxxxxxxxxxxx>
Cc: <rf13@xxxxxxxxxxxxxxxxxxxxxxxx>, freeciv development list <freeciv-dev@xxxxxxxxxxx>
Subject: [Freeciv-Dev] Re: Compiler-warnings
From: Stepan Roh <stepan@xxxxxxxx>
Date: Wed, 24 Jan 2001 23:05:26 +0100 (CET)


On Wed, 24 Jan 2001, Tony Stuckey wrote:

>       It's probably a style error to use signed chars as array
> subscripts.  Explicitly adding unsigned to silence these warnings should be
> an acceptable patch, once that has been verified to not add any
> out-of-range issues.
>
> int has_capability(const char *cap, const char *capstr)
> {
>   char *capstr_, *token, *next;
>   int res=0, finished=0;
>
>   token = capstr_ = mystrdup(capstr);
>   do {
>     /* skip leading whitespace */
>     while (isspace(*token))
>       token++;
>
>       Compiling on a sparc running Solaris 8 using GCC, I get this style
> of error on the while (isspace(*token)) line above, which does not have any
> obvious array subscripting going on, though.

I finally recalled what's the point here (I had this problem last year
when testing Allegro lib on IRIX). There are two kinds of libcs (which I
know) : traditional and GNU. Traditional libcs (such as those on Solaris
and IRIX - both have their roots on AT&T Unix) have ctype.h functions
#defined as (taken from Solaris's libc - (c) Sun Microsystems Inc.) :

#define isspace(c)      ((_ctype + 1)[c] & _S)

(they are inlined when using C++ with argument type of int, but not when
using C).  This causes warning if c is of type signed char (which (for
some reason I don't know - maybe tradition?)  char is defined as on every
C compiler I know). And it should cause crash (in most cases) when using
value of signed char outside <-1,127> - for example accented chars in some
encodings.

GNU libc has this macro :

#define __isctype(c, type) \
  (__ctype_b[(int) (c)] & (unsigned short int) type)

which recasts c to type int. And they also have __ctype_b starting at
negative subscript values, so it won't crash with signed chars.

Have a nice day.

Stepan Roh




[Prev in Thread] Current Thread [Next in Thread]