From: "Gaurav Gautam, Noida" <gauravga@noida.hcltech.com>
To: "Dave Korn" <dave.korn@artimi.com>,
"John Love-Jensen" <eljay@adobe.com>, <gcc@gcc.gnu.org>,
"MSX to GCC" <gcc-help@gcc.gnu.org>
Subject: RE: No effect of -fshort-enums..is it a bug
Date: Fri, 23 Sep 2005 14:06:00 -0000 [thread overview]
Message-ID: <40CC5CC7CDACC048B1299C57025E330C01009D59@HSDLNTD1110010.noida.hcltech.com> (raw)
>
> > 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....
next reply other threads:[~2005-09-23 14:06 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-09-23 14:06 Gaurav Gautam, Noida [this message]
2005-09-23 14:21 ` John Love-Jensen
-- strict thread matches above, loose matches on Subject: below --
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 13:35 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
2005-09-21 12:17 Gaurav Gautam, Noida
2005-09-21 12:39 ` Daniel Jacobowitz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=40CC5CC7CDACC048B1299C57025E330C01009D59@HSDLNTD1110010.noida.hcltech.com \
--to=gauravga@noida.hcltech.com \
--cc=dave.korn@artimi.com \
--cc=eljay@adobe.com \
--cc=gcc-help@gcc.gnu.org \
--cc=gcc@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).