www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/06/08/08:50:54

Message-Id: <3.0.5.32.19980608144947.009c2550@dictator.nt.tuwien.ac.at>
Date: Mon, 08 Jun 1998 14:49:47 +0200
To: djgpp AT delorie DOT com
From: Anton Helm <tony AT nt DOT tuwien DOT ac DOT at>
Subject: Bugs in GCC install (Was: Re: Warnings)
In-Reply-To: <MPG.fe0cda48d30812698970a@news.virgin.net>
References: <35715AA9 DOT 4222FD24 AT net4you DOT co DOT at>
<35718841 DOT 1129 AT cs DOT com>
<slrn6n7qds DOT 46 DOT loki AT anima DOT nectar DOT com DOT au>
<357488F9 DOT 6054 AT cs DOT com>
Mime-Version: 1.0

At 00:21 05.06.98 +0100, you wrote:
>death.c:6377: warning: array subscript has type 'char'

I had problems with such warnings before. They came up with
GCC v2.8.0 on some unix systems (HPUX 9.0.x, Solaris 2.5.1, DECUX) 
but didn't occur in DJGPP (and HPUX 10.20).

What's happening:

If c is a char type variable and

isalpha(c) is evaluated then the above warning is printed.

isalpha() is a function declared in ctype.h
islapha() is declared having an argument of type int.

See chapter 7.3 of ANSI C standard for details.

Usually this function (and other similar ones) are
implemented as macros. These macros vary from one
OS to another...

Using a char type parameter will result in the above warning
if it is passed to an array subscript - the OS' macro usually 
doesn't cast the parameter (neither impicitly nor explicitly).

If GCC wants to keep this type of warning from beeing ignored, 
the install procedure should test ctype.h for
such buggy implementations and fix them (as it does for various 
other header files).

Some simple fixes would be:
1) use an explicit cast whereever the argument of isalpha()
   is used.
2) add 0 to the subscript. This will cast it to an int implicitly.
   (I've done so at my Solaris workstation and it works fine)




Below some implementations of isalpha() in various OS.
******************************************************************
DJGPP:
#define isalpha(c) (__dj_ctype_flags[((c)&0xff)+1] & __dj_ISALPHA)

The '+1' casts the contents of [] to an int.
Therefore type of subscript is int -> no warning.


HPUX 10.20:
extern int __alnum;
#define isalpha(__c)  (__alnum = (__c), __alnum == -1 ? 0       \
                  : __SB_masks ? __SB_masks[__alnum] & _ISALPHA \
                  : _isalpha(__alnum))

__alnum is of type int, cast by assignment -> no warning.


Solaris 2.5.1:
#define isalpha(c)  ((__ctype + 1)[c] & (_U | _L))

The subscript is passed directly from the argument c of isalpha().
Subscript is of type char -> warning.
Bugfix by me:
#define isalpha(c)  ((__ctype + 1)[c+0] & (_U | _L))



DECUX:
#include <sys/localedef.h>
#define isalpha(c)  _ISMACRO(c,_ISALPHA)

and from sys/localedef.h
#define _ISMACRO(c,cmsk) ((_METHOD(__lc_ctype,_MNAME(iswctype)) == 0L) \
                ? (int) (__lc_ctype->_mask[c] & (cmsk)) \
                : _METHOD(__lc_ctype,_MNAME(iswctype)) (c,cmsk,__lc_ctype))

Again the c is passed directly into a subscript -> warning.


HPUX 9.x
#define isalpha(__c)        (__ctype2[__c]&(_A))

As above.


*****************************************************

I know this is more related tp GCC then to DJGPP,
but I would like to hear some other opinions before
writing a bug-report.


Regards,


Tony









**************************************************************
Dipl.-Ing. Anton HELM   *T*  mailto:tony AT nt DOT tuwien DOT ac DOT at
Institut fuer           *U*  http://www.nt.tuwien.ac.at/~tony/
Nachrichtentechnik und  *W*  http://www.nt.tuwien.ac.at/
Hochfrequenztechnik     *I*  talkto:tony AT eagle DOT nt DOT tuwien DOT ac DOT at
Guszhausstr. 25/389     *E*  phoneto:+43-1-58801-3520
A-1040 Wien, AUSTRIA    *N*  faxto:+43-1-5870583
**************************************************************
finger -l tony AT penguin DOT nt DOT tuwien DOT ac DOT at      for PGP public key
**************************************************************

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019