Thanks for the reply, but I did not get the answer to my question.
My question is:
In the below mentioned program
#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.
Please confirm which of the two outputs is correct and why is there a
difference in the output of two versions of compiler?
Thanks
Gaurav gautam
> -----Original Message-----
> From: Gaurav Gautam, Noida
> Sent: Wednesday, September 21, 2005 7:04 PM
> To: '[email protected]'; '[EMAIL PROTECTED]'
> Cc: 'Daniel Jacobowitz'
> 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:[EMAIL PROTECTED]
> > Sent: Wednesday, September 21, 2005 6:10 PM
> > To: Gaurav Gautam, Noida
> > Cc: [email protected]; [EMAIL PROTECTED]
> > 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