This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
RE: Traditional numbers
- To: 'James Grosbach' <james dot grosbach at microchip dot com>, gcc at gcc dot gnu dot org
- Subject: RE: Traditional numbers
- From: Bernard Dautrevaux <Dautrevaux at microprocess dot com>
- Date: Mon, 30 Jul 2001 17:24:48 +0200
> -----Original Message-----
> From: James Grosbach [mailto:james.grosbach@microchip.com]
> Sent: Monday, July 30, 2001 5:09 PM
> To: gcc@gcc.gnu.org
> Subject: Re: Traditional numbers
>
>
> On Fri, Jul 27, 2001 at 06:35:48PM +0100, Neil Booth wrote:
> > int main()
> > {
> > #if 0xffffffff < 0
> > puts("cpp:negative");
> > #else
> > puts("cpp:positive");
> > #endif
> > puts(0xffffffff < 0 ? "c:negative" : "c:positive");
> > return 0;
> > }
> > bash$ gcc3 -traditional a.c && ./a.out
> > cpp:positive
> > c:negative
> >
> > Does the list agree that the above behaviour is a bug?
>
> Yes. According to my understanding of the standard, the compiler
> is in error. The integer constant should be of the first type
> from the following list into which the value will fit: int,
> unsigned int, long int, unsigned long int. The value 0xffffffff
> will not fit in a signed 32-bit type, so the type of the
> constant is unsigned int, and the comparison should yield
> false.
I would agree with you, except that the "-traditional" flag here is bending
gcc towards "traditional" C, as opposed to ANSI C. I agree that in ANSI C
0xffffffff is positive; however in traditional C is may be (and often is)
negative :-)
HTH
Bernard.
PS: in this case the problem is probably in the preprocessor, which with
"-traditional" should keep the same conventions as the compiler for the sake
of consistency, although K&R was not precise enough to be able to qualify
this of a BUG :-)
--------------------------------------------
Bernard Dautrevaux
Microprocess Ingenierie
97 bis, rue de Colombes
92400 COURBEVOIE
FRANCE
Tel: +33 (0) 1 47 68 80 80
Fax: +33 (0) 1 47 88 97 85
e-mail: dautrevaux@microprocess.com
b.dautrevaux@usa.net
--------------------------------------------