From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mengyan1223.wang (mengyan1223.wang [89.208.246.23]) by sourceware.org (Postfix) with ESMTPS id 09D7E3858C3A for ; Thu, 14 Oct 2021 15:24:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 09D7E3858C3A Received: from localhost.localdomain (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature ECDSA (P-384) server-digest SHA384) (Client did not present a certificate) (Authenticated sender: xry111@mengyan1223.wang) by mengyan1223.wang (Postfix) with ESMTPSA id 3A3B0660AA; Thu, 14 Oct 2021 11:24:38 -0400 (EDT) Message-ID: Subject: Re: =?gb2312?Q?=BB=D8=B8=B4=A3=BA?= Inconsistency with C language standard From: Xi Ruoyao To: 3497650172 <3497650172@qq.com> Cc: gcc-help@gcc.gnu.org Date: Thu, 14 Oct 2021 23:24:34 +0800 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.42.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3027.0 required=5.0 tests=BAYES_00, BODY_8BITS, CHARSET_FARAWAY_HEADER, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, JMQ_SPF_NEUTRAL, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=no autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-help@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-help mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Oct 2021 15:24:43 -0000 On Thu, 2021-10-14 at 20:58 +0800, 3497650172 wrote: > In Visual Studio, if the value of enumeration constant exceeds the > range that int can represent, hermit conversion will be performed, > such as the following code: > ———————————————————————— > #include > > enum A { > MAX= 4294967295 > }; > int main() { > if (MAX < 1) { > printf("test"); > } > } > ———————————————————————— > In Visual Studio, the value of Max is - 1, so "test" will be output. > but in GCC, the value of Max is 4294967295, so "test" will not be > output. > I think the Visual Studio is consistent with the C language standard, > but GCC is inconsistent with the standard. As I've explained, you are invoking undefined behavior, so a conforming compiler can do anything. The standard is not "you think". -- Xi Ruoyao School of Aerospace Science and Technology, Xidian University