Re: 回复: Inconsistency with C language standard

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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<stdio.h>
> 
> 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 <xry111@xxxxxxxxxxxxxxxx>
School of Aerospace Science and Technology, Xidian University



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux