From: Xi Ruoyao <xry111@mengyan1223.wang>
To: Jonathan Wakely <jwakely.gcc@gmail.com>, 3497650172 <3497650172@qq.com>
Cc: gcc-help <gcc-help@gcc.gnu.org>
Subject: Re: Inconsistency with C language standard
Date: Thu, 14 Oct 2021 18:46:55 +0800 [thread overview]
Message-ID: <c0522fbdc41bea96c8f732f2adc9b95280bbda39.camel@mengyan1223.wang> (raw)
In-Reply-To: <CAH6eHdRB6WdVNQRrdEX71mAr0HnRk49USM_1JQvDV0rg5tMjzg@mail.gmail.com>
On Thu, 2021-10-14 at 07:38 +0100, Jonathan Wakely via Gcc-help wrote:
> On Thu, 14 Oct 2021, 03:29 3497650172 via Gcc-help,
> <gcc-help@gcc.gnu.org>
> wrote:
>
> > The C language standard specifies that the "enum" constant is of type
> > int,
> > but GCC supports all integers.And i did not find this discrepancy in
> > the
> > official manual.
>
>
> There is not discrepancy, GCC conforms to the standard. It is documented
> at
> https://gcc.gnu.org/onlinedocs/gcc/Structures-unions-enumerations-and-bit-fields-implementation.html
>
> Did I not find it or did the official website document not explain it at
> > all?
>
>
> You didn't find it.
>
> How do I know all the differences?
>
>
> Read the manual
> https://gcc.gnu.org/onlinedocs/gcc/C-Implementation.html
Hi Jonathan,
I think the OP is refering to C99 6.4.4.3p2:
> An identifier declared as an enumeration constant has type int.
There is some tricky difference between the concepts "the type of an
enumeration constant" and "the type compatible to an enumeration type".
However, the standard (C99, 6.7.2.2 p2) also says:
> The expression that defines the value of an enumeration constant shall be an integer
> constant expression that has a value representable as an int.
So if you specify a value which doesn't fit in an int, you're invoking
an undefined behavior. For example:
enum { x = 1145141919810L };
invokes undefined behavior and the compiler can do anything. "anything"
includes chosing another type for x, and/or even worse.
With -Wpedantic:
> t.c:4:12: warning: ISO C restricts enumerator values to range of 'int'
> [-Wpedantic]
> 4 | enum { x = 1145141919810L };
> | ^~~~~~~~~~~~~~
--
Xi Ruoyao <xry111@mengyan1223.wang>
School of Aerospace Science and Technology, Xidian University
next prev parent reply other threads:[~2021-10-14 10:46 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-14 2:28 3497650172
2021-10-14 6:38 ` Jonathan Wakely
2021-10-14 10:46 ` Xi Ruoyao [this message]
[not found] ` <tencent_7A3E0B9A44D54C42051CA77EC71741F55005@qq.com>
2021-10-14 15:24 ` 回复: " Xi Ruoyao
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=c0522fbdc41bea96c8f732f2adc9b95280bbda39.camel@mengyan1223.wang \
--to=xry111@mengyan1223.wang \
--cc=3497650172@qq.com \
--cc=gcc-help@gcc.gnu.org \
--cc=jwakely.gcc@gmail.com \
/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).