[Freeciv-Dev] Re: Compiler-warnings
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
On Wed, Jan 24, 2001 at 11:05:26PM +0100, Stepan Roh wrote:
>
>
> 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.
[ Negative subscript values? Is this a gnu extension? What are the
semantics? What would you expect from:
-------
#include <stdio.h>
int main()
{
int x,arr[10],y,i;
for(i=0;i<10;i++)
arr[i]=i;
x=42;
y=43;
printf("[-1]=%d\n",arr[-1]);
printf("[10]=%d\n",arr[10]);
return 0;
}
-------
I expected 42 and 43 and missed. Now please add -O and test again. ]
So we can add a wrapper for is* or make the strings unsigned char *?!
Raimar
--
email: rf13@xxxxxxxxxxxxxxxxx
Windows: Where do you want to go today?
Linux: Where do you want to go tomorrow?
BSD: Are you guys coming or what?
- [Freeciv-Dev] Re: Compiler-warnings, (continued)
- [Freeciv-Dev] Re: Compiler-warnings, Gerhard Killesreiter, 2001/01/24
- [Freeciv-Dev] Re: Compiler-warnings, Dirk Stoecker, 2001/01/24
- [Freeciv-Dev] Re: Compiler-warnings, Gerhard Killesreiter, 2001/01/24
- [Freeciv-Dev] Re: Compiler-warnings, Raimar Falke, 2001/01/24
- [Freeciv-Dev] Re: Compiler-warnings, Gerhard Killesreiter, 2001/01/24
- [Freeciv-Dev] Re: Compiler-warnings, Raimar Falke, 2001/01/24
- [Freeciv-Dev] Re: Compiler-warnings, Stepan Roh, 2001/01/24
- [Freeciv-Dev] Re: Compiler-warnings, Raimar Falke, 2001/01/24
- [Freeciv-Dev] Re: Compiler-warnings, Tony Stuckey, 2001/01/24
- [Freeciv-Dev] Re: Compiler-warnings, Stepan Roh, 2001/01/24
- [Freeciv-Dev] Re: Compiler-warnings,
Raimar Falke <=
- [Freeciv-Dev] Re: Compiler-warnings, Falk Hueffner, 2001/01/24
- [Freeciv-Dev] Re: Compiler-warnings, Dirk Stoecker, 2001/01/25
[Freeciv-Dev] Re: Compiler-warnings, Reinier Post, 2001/01/24
[Freeciv-Dev] Re: Compiler-warnings, Dirk Stoecker, 2001/01/24
|
|