什么是betweeen C(99)和C ++(11)不兼容的区别在哪里? [英] What are the incompatible differences betweeen C(99) and C++(11)?

查看:286
本文介绍了什么是betweeen C(99)和C ++(11)不兼容的区别在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题是由replie(S)到帖子引发由香草萨特他解释MS决定不支持/做出C99编译器,但只是与那些在C C(99)的特性去++(11)的标准呢。

答道:


  

(...)C是重要的,值得至少关注的一点。


  
  

有是对现有code的很多在那里,是有效的C,但不
  有效的C ++。即code是不太可能被改写(...)


由于我只在MS的C ++程序,我真的不知道纯C说好了,也就是说我的C ++的哪些细节没有现成的图片 - 我使用的语言是不是在C(99)和我有一点蛛丝马迹,其中一些C99 code是行不通的,是一个C ++编译器。

请注意,我知道了C99仅限制关键字这对我的看起来的有很窄的应用程序及关于可变长度阵列(其中,我不知道如何wides $ p $垫或重要的他们)。

另外,我很感兴趣,是否有重要的语义差异或陷阱,即C(99)code,它会的编译的Ç下++(11),但做一些不同的东西与C ++编译器比C编译器。


快速链接:从外部的答案资源:


解决方案

如果您从C和C的公共子集开始++,有时也被称为清洁C(这是不太C90),你必须要考虑3种类型的不兼容问题:


  1. 其他C ++ featues这使得合法的C非法C ++

    有关这方面的例子是,可用于在C或转换其在C含蓄,但需要在C ++中显式类型转换的标识符的C ++关键字。

    这可能是最主要的原因,微软仍然船舶一个C前端在所有。否则,遗留code,不作为编译C ++就必须重写


  2. 其他C的特征这是不是C ++的一部分

    C语言没有停止C ++中分叉后演变。一些例子是变长数组,指定初始化和限制。这些功能可以说是相当方便的,但都没有任何的C ++标准的一部分,其中一些可能永远不会使其在


  3. 功能这是在C和C ++提供,但有不同的语义

    有关这方面的一个例子是 const的联动​​对象或在线功能。


C99和C ++ 98 之间不兼容的名单可以在这里(其中已经提到发现由MAT)。

虽然C ++ 11和C11得到了某些方面更密切(可变参数宏现在可以在C ++中,变长数组现在是一个可选的C语言功能),不兼容的名单也有所增长(如通用选择在C与汽车键入说明符在C ++中)。

顺便说一句,虽然微软已经采取了一些热量放弃C(这是不是最近一),决定据我所知实际上已经采取措施,做一些关于它的开源社区没有一个人:这将是完全有可能通过C到C ++编译器提供现代C的许多功能,尤其是当你考虑到的他们中的一些微不足道的实施。其实,这是可能的,现在使用科莫C / C ++,它不支持C99。

然而,这不是一个真正的pressing问题:就个人而言,我用GCC和锵在Windows上相当舒适,并且有专用的替代MSVC为好,如Pelles C或英特尔的编译器。

This question was triggered by replie(s) to a post by Herb Sutter where he explained MS's decision to not support/make a C99 compiler but just go with the C(99) features that are in the C++(11) standard anyway.

One commenter replied:

(...) C is important and deserves at least a little bit of attention.

There is a LOT of existing code out there that is valid C but is not valid C++. That code is not likely to be rewritten (...)

Since I only program in MS C++, I really don't know "pure" C that well, i.e. I have no ready picture of what details of the C++-language I'm using are not in C(99) and I have little clues where some C99 code would not work as-is in a C++ compiler.

Note that I know about the C99 only restrict keyword which to me seems to have very narrow application and about variable-length-arrays (of which I'm not sure how widespread or important they are).

Also, I'm very interested whether there are any important semantic differences or gotchas, that is, C(99) code that will compile under C++(11) but do something differently with the C++ compiler than with the C compiler.


Quick links: External resources from the answers:

解决方案

If you start from the common subset of C and C++, sometimes called clean C (which is not quite C90), you have to consider 3 types of incompatibilities:

  1. Additional C++ featues which make legal C illegal C++

    Examples for this are C++ keywords which can be used as identifiers in C or conversions which are implicit in C but require an explicit cast in C++.

    This is probably the main reason why Microsoft still ships a C frontend at all: otherwise, legacy code that doesn't compile as C++ would have to be rewritten.

  2. Additional C features which aren't part of C++

    The C language did not stop evolving after C++ was forked. Some examples are variable-length arrays, designated initializers and restrict. These features can be quite handy, but aren't part of any C++ standard, and some of them will probably never make it in.

  3. Features which are available in both C and C++, but have different semantics

    An example for this would be the linkage of const objects or inline functions.

A list of incompatibilities between C99 and C++98 can be found here (which has already been mentioned by Mat).

While C++11 and C11 got closer on some fronts (variadic macros are now available in C++, variable-length arrays are now an optional C language feature), the list of incompatibilities has grown as well (eg generic selections in C and the auto type-specifier in C++).

As an aside, while Microsoft has taken some heat for the decision to abandon C (which is not a recent one), as far as I know no one in the open source community has actually taken steps to do something about it: It would be quite possible to provide many features of modern C via a C-to-C++ compiler, especially if you consider that some of them are trivial to implement. This is actually possible right now using Comeau C/C++, which does support C99.

However, it's not really a pressing issue: Personally, I'm quite comfortable with using GCC and Clang on Windows, and there are proprietary alternatives to MSVC as well, eg Pelles C or Intel's compiler.

这篇关于什么是betweeen C(99)和C ++(11)不兼容的区别在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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