为什么不同的C编译器为C程序提供不同的输出? [英] Why can different C compilers give different outputs for a C program?

查看:145
本文介绍了为什么不同的C编译器为C程序提供不同的输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个疑问,为什么它发生,不同的编译器给不同的输出到同一个C程序。如果有一个标准C,那么为什么这些着名的编译器不使用完全。
输出的差异是由16位32位编译器引起的,所以这些问题都是有区别的。

解决方案<



首先,即使程序被正确实现,它的行为可能依赖于实现定义语言特性。例如,不同的实现对基本整数类型可以有不同的范围。



其次,程序可能会被破坏。在这种情况下,一个破碎的程序是一个依赖于语言未定义或未指定的行为的程序。这个程序将以某种方式工作,但它的实际行为将取决于不可预测的因素,因此将是不一致的。



练习显示,在许多如果不是大多数)的情况下,当人们抱怨不一致的行为C程序,他们实际上没有意识到他们正在处理一个破碎的程序。


I have a doubt why it happens that different compilers give different outputs to a same C program.If there is an standard C then why these famous compiler dont use that completely. the difference in output is caused by 16-bit , 32-bit compilers so what are all those issues which makes the difference.

解决方案

The language standard leaves several degrees of freedom to the implementations.

Firstly, even if the program is implemented correctly, its behavior might depend on implementation-defined language features. For example, different implementations can have different ranges for basic integer types.

Secondly, the program might simply be broken. A broken program in this context is a program that relies on behavior that is either undefined or unspecified by the language. This program will appear to "work" in some way, but its actual behavior will depend on unpredictable factors and, therefore, will be inconsistent.

Practice show that in many (if not most) cases when people complain about inconsistently behaving C programs, they are actually failing to realize that they are dealing with a broken program.

这篇关于为什么不同的C编译器为C程序提供不同的输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆