This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: No effect of -fshort-enums..is it a bug


> 
> > Hi Gaurav,
> >
> >> Please confirm which of the two outputs is correct and why is there
a
> > difference in the output of two versions of compiler?
> >
> > Both outputs are "correct".
> >
> 
> 
>   No, the standard is entirely unambiguous:
> 
> --------------------------------------------------------
> 6.4.4.3 Enumeration constants
> Syntax
> 1 enumeration-constant:
> identifier
> Semantics
> 2 An identifier declared as an enumeration constant has type int.
> --------------------------------------------------------
> 
>   The enumeration constants denoted by the identifiers a, b, and c are
> therefore of type int and must have size 4 (on a standard 32-bit
system),
> regardless of the size of the enumerated type aa.

Thank you all for your replies. But I have another question to ask
Consider another example

#include <stdio.h>
int main()
{
  enum ff {
        p = 0, q = 4294967295, r              
        };
        printf("size = %d  %d %d\n", sizeof(enum ff),sizeof(q),
sizeof(r));
        printf("value= %d  %d %d\n", p,q,r);
}

Its output is with default options on gcc :
size = 8  8 8
value= 0  -1 0

Enumerator are supposed to be int and must have size 4. why are they
being treated as long here and taking 8 bytes? Size of int on my machine
is 4.

Also the compiler doesn't even gives a warning when the tc is compiled.
> 
> 
> > (Neither output is compliant to the standard, of course, as -fshort-
> enums
> > is a deviation from the standard.)
> 
>   Nope, the standard is entirely unambiguous:
> 
> --------------------------------------------------------
> 6.7.2.2 Enumeration specifiers
> 
> 4 Each enumerated type shall be compatible with an integer type. The
> choice
> of type is
> implementation-defined,97) but shall be capable of representing the
values
> of all the
> members of the enumeration. The enumerated type is incomplete until
after
> the } that
> terminates the list of enumerator declarations.
> --------------------------------------------------------
> 
>   The choice of what integer type to use to store a value of an
enumerated
> type is implementation-defined, and if a char is big enough to
represent
> all
> the values, the implementation is at liberty to use a char.
> 
> 
> 
>     cheers,
>       DaveK
> --
> Can't think of a witty .sigline today....


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]