public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* RE: No effect of -fshort-enums..is it a bug
@ 2005-09-21 13:35 Gaurav Gautam, Noida
  2005-09-21 14:19 ` Daniel Jacobowitz
  2005-09-21 15:42 ` Andreas Schwab
  0 siblings, 2 replies; 22+ messages in thread
From: Gaurav Gautam, Noida @ 2005-09-21 13:35 UTC (permalink / raw)
  To: gcc, gcc-help; +Cc: Daniel Jacobowitz

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

^ permalink raw reply	[flat|nested] 22+ messages in thread
* RE: No effect of -fshort-enums..is it a bug
@ 2005-09-23 14:06 Gaurav Gautam, Noida
  2005-09-23 14:21 ` John Love-Jensen
  0 siblings, 1 reply; 22+ messages in thread
From: Gaurav Gautam, Noida @ 2005-09-23 14:06 UTC (permalink / raw)
  To: Dave Korn, John Love-Jensen, gcc, MSX to GCC


> 
> > 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....

^ permalink raw reply	[flat|nested] 22+ messages in thread
* RE: No effect of -fshort-enums..is it a bug
@ 2005-09-22 13:40 Gaurav Gautam, Noida
  2005-09-22 15:32 ` Neil Booth
  2005-09-22 15:36 ` John Love-Jensen
  0 siblings, 2 replies; 22+ messages in thread
From: Gaurav Gautam, Noida @ 2005-09-22 13:40 UTC (permalink / raw)
  To: Gaurav Gautam, Noida, gcc, gcc-help

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: 'gcc@gcc.gnu.org'; 'gcc-help@gcc.gnu.org'
> 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: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

^ permalink raw reply	[flat|nested] 22+ messages in thread
* No effect of -fshort-enums..is it a bug
@ 2005-09-21 12:17 Gaurav Gautam, Noida
  2005-09-21 12:39 ` Daniel Jacobowitz
  0 siblings, 1 reply; 22+ messages in thread
From: Gaurav Gautam, Noida @ 2005-09-21 12:17 UTC (permalink / raw)
  To: gcc, gcc-help

Hi,

I have compiled a testcase

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;
}

On gcc (GCC) 4.1.0 20050915 (experimental) with the following option -fshort-enums.

The option -fshort-enums has no effect and the output is same as it is without this option.


I also tried the same tc on gcc (GCC) 3.3.1 (SuSE Linux). But in this case the output changed with and without this option.

I am using an SuSe linux -- X86_AMD64 machine.

I think it's a bug. Can anybody please confirm?

Thanks
Gaurav

^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2005-09-23 14:21 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-09-21 13:35 No effect of -fshort-enums..is it a bug Gaurav Gautam, Noida
2005-09-21 14:19 ` Daniel Jacobowitz
2005-09-21 14:55   ` Robert Dewar
2005-09-21 17:26     ` Daniel Jacobowitz
2005-09-21 15:42 ` Andreas Schwab
2005-09-23  9:16   ` Bernhard R. Link
  -- strict thread matches above, loose matches on Subject: below --
2005-09-23 14:06 Gaurav Gautam, Noida
2005-09-23 14:21 ` John Love-Jensen
2005-09-22 13:40 Gaurav Gautam, Noida
2005-09-22 15:32 ` Neil Booth
2005-09-22 15:36 ` John Love-Jensen
2005-09-22 16:15   ` Daniel Jacobowitz
2005-09-22 16:20   ` Dave Korn
2005-09-22 16:28     ` John Love-Jensen
2005-09-22 16:41       ` Gabriel Dos Reis
2005-09-22 16:51     ` Robert Dewar
2005-09-22 18:31       ` Daniel Jacobowitz
2005-09-22 19:03         ` Paul Brook
2005-09-22 16:26   ` Gabriel Dos Reis
2005-09-22 16:33     ` John Love-Jensen
2005-09-21 12:17 Gaurav Gautam, Noida
2005-09-21 12:39 ` Daniel Jacobowitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).