This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
RE: No effect of -fshort-enums..is it a bug
- From: "Gaurav Gautam, Noida" <gauravga at noida dot hcltech dot com>
- To: <gcc at gcc dot gnu dot org>, <gcc-help at gcc dot gnu dot org>
- Cc: "Daniel Jacobowitz" <drow at false dot org>
- Date: Wed, 21 Sep 2005 19:03:49 +0530
- Subject: RE: No effect of -fshort-enums..is it a bug
Thanks for the reply,
But why is there a difference in the output of same tc, with an old gcc
compiler and a new version of compiler.
Was there a bug in the earlier gcc.
I have a doubt.
Gcc manual says that
"-fshort-enums
Allocate to an enum type only as many bytes as it needs for the
declared range of possible values. Specifically, the enum type will be
equivalent to the smallest integer type which has enough room."
Does -fshort-enum guides the size of enumeration type or the size of
enumerator constant ?
After modifying the tc as
#include <stdio.h>
int main()
{
enum aa {
a = 0, b =127 , c
};
printf("size = %d %d %d\n", sizeof(enum aa),sizeof(b),
sizeof(c));
printf("value= %d %d %d\n", a,b,c);
return 0;
)
The output is
size = 1 1 1
value= 0 127 128
when gcc (GCC) 3.3.1 (SuSE Linux) is used with -fshort-enums.
And
size = 1 4 4
value= 0 127 128
when (GCC) 4.1.0 20050915 (experimental) is used with -fshort-enums.
Which of the two output is standard confirming.?
> -----Original Message-----
> From: Daniel Jacobowitz [mailto:drow@false.org]
> Sent: Wednesday, September 21, 2005 6:10 PM
> To: Gaurav Gautam, Noida
> Cc: gcc@gcc.gnu.org; gcc-help@gcc.gnu.org
> Subject: Re: No effect of -fshort-enums..is it a bug
>
> On Wed, Sep 21, 2005 at 05:46:58PM +0530, Gaurav Gautam, Noida wrote:
> > int main()
> > {
> > enum aa {
> > a = 0, b =127 , c
> > };
> >
> > printf("size = %d %d %d\n", sizeof(a),sizeof(b),
sizeof(c));
> > printf("value= %d %d %d\n", a,b,c);
> > return 0;
> > }
>
> > The option -fshort-enums has no effect and the output is same as it
is
> without this option.
>
> It's not a bug. Add sizeof(enum aa) to your printf; _that_ will be
> affected by -fshort-enums. The type of the enumerators remains int.
>
> --
> Daniel Jacobowitz
> CodeSourcery, LLC