cvs.gedasymbols.org/archives/browse.cgi   search  
Mail Archives: djgpp/1998/08/25/05:03:38

Date: Tue, 25 Aug 1998 11:01:27 +0200
From: Hans-Bernhard Broeker <broeker AT physik DOT rwth-aachen DOT de>
Message-Id: <199808250901.LAA24655@acp3bf.physik.rwth-aachen.de>
To: malfer AT teleline DOT es
Cc: djgpp AT delorie DOT com
Subject: Re: Possible bug in GCC
Newsgroups: comp.os.msdos.djgpp
Organization: RWTH Aachen, III. physikalisches Institut B

In article <35E1A919 DOT 45F5 AT teleline DOT es> you wrote:
> #include <conio.h>
> typedef enum { V1, V2, V3 } Tipo;
> int main()
> {
>   Tipo i;
>   i = -1;
>   if( i < 0 )
>     puts( "Negative number" );
>   else
>     puts( "Positive number" );
> }

> I think it's a GCC bug because the K&R book (second ed.) say enum types
> default to int (not unsigned as DJGPP does). I know I must report that
> to the GCC maintainer, but I want to know yours opinions first.

According to my understanding of the ANSI C standard, this is not a
gcc bug, as this behaviour is left 'implementation-defined', there.
To quote the ANSI C9x working draft:

       [#4] Each  enumerated  type  shall  be  compatible  with  an
       integer type.  The choice of type is implementation-defined,
       but shall be capable of representing the values of  all  the
       members of the enumeration.

There's no word there about wether this integer type is signed or
unsigned. It may even end up being an unsigned char, as long as that's
big enough to hold all the tag values of the given enum.  The
enumeration constants themselves are a different issue: they are
*ints*, always. But the enum type may be anything from char up to int,
or maybe even long long int...

For a more definite answer, I think you should consult
comp.lang.c.moderated or comp.std.c, first, before claiming a bug in
gcc.

--
Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de)
Even if all the snow were burnt, ashes would remain.

- Raw text -


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