问题描述
我刚刚阅读:。据我所知,有3种不同版本的C被广泛使用:C89,C99和C11。我的问题涉及不同版本的源代码的兼容性。
假设我要编写一个程序(由于它是最新版本,请使用C11)并导入一个用C89编写的库。根据C11规范编译所有文件时,这两个版本是否可以正常工作?
I just read: C Wikipedia entry. As far as I know there are 3 different versions of C that are widely used: C89, C99 and C11. My question concerns the compatibility of source code of different versions.Suppose I am going to write a program (in C11 since it is the latest version) and import a library written in C89. Are these two versions going to work together properly when compiling all files according to the C11 specification?
问题1 :
较新的C版本,即较旧的C版本的C99,C11超集?通过超集,我的意思是,当按照较新的C规范进行编译时,旧代码将无错误且具有相同的含义进行编译。
Question 1:Are the newer versions of C i.e. C99, C11 supersets of older C versions? By superset I mean, that old code will compile without errors and the same meaning when compiled according to newer C specifications.
我刚刚读到,//在C89和C99中具有不同的含义。除了此功能之外,还有C89的C99和C11超集吗?
I just read, that the // has different meanings in C89 and C99. Apart from this feature, are C99 and C11 supersets of C89?
如果问题1的答案为否,那么我还会得到另外2个问题。
If the answer to Question 1 is no, then I got another 2 questions.
-
如何将旧代码移植到新版本?是否有解释此程序的文件?
How to 'port' old code to the new versions? Is there a document which explains this procedure?
使用C89,C99或C11更好吗?
Is it better to use C89 or C99 or C11?
谢谢您的帮助。
编辑:将ISO C更改为C89。
EDIT: changed ISO C to C89.
推荐答案
有很多差异,两者都很大而又很微妙。大多数更改是添加了新功能和库。 C99和C11不是C90的超集,尽管已经做了很多努力来确保向后兼容。但是,C11大部分是C99的超集。
There are many differences, big and subtle both. Most changes were adding of new features and libraries. C99 and C11 are not supersets of C90, although there was a great deal of effort made to ensure backwards-compatibility. C11 is however mostly a superset of C99.
从C90移植时,如果代码编写得不好,仍然会破坏旧代码。 C99语言特别禁止使用各种形式的隐式int和隐式函数声明。 C11禁止 gets
函数。
Still older code could break when porting from C90, in case the code was written poorly. Particularly various forms of "implicit int" and implicit function declarations were banned from the language with C99. C11 banned the gets
function.
完整的更改列表可以在,其中第三版是指C11,第二版是指C99。
A complete list of changes can be found in the C11 draft page 13 of the pdf, where "the third edition" refers to C11 and "the second edition" refers to C99.
我不知道任何此类文档。如果您有良好的代码,则移植很容易。如果代码烂了,移植会很痛苦。至于实际的移植过程,如果您了解C99和C11的基础知识,这将很容易,因此最好的选择是找到可解决C99 / C11的可靠学习资源。
I'm not aware about any such document. If you have good code, porting is easy. If you have rotten code, porting will be painful. As for the actual porting procedure, it will be easy if you know the basics of C99 and C11, so the best bet is to find a reliable source of learning which addresses C99/C11.
从C99到C11的移植应该很容易。
Porting from C99 to C11 should be effortless.
最好使用C11,因为这是当前标准。 C99和C11都包含各种语言错误修复,并引入了新的有用的功能。
It is best to use C11 as that is the current standard. C99 and C11 both contained various "language bug fixes" and introduced new, useful features.
这篇关于C89 / C90,C99和C11的兼容性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!