简体   繁体   English

C99标准有什么意义?

[英]What is the point of the C99 standard?

C99 adds several useful features to the language, yet I find it difficult to recommend any practice which depends upon C99. C99为该语言添加了一些有用的功能,但我发现很难推荐任何依赖于C99的练习。 The reason for this is because there are few (any?) actual implementations of the C99 language. 这是因为C99语言的实际实现很少(任何?)。 Sure, there is limited support in a few compilers, but nobody wants spend the time to write C code only to have it be unportable. 当然,在一些编译器中支持有限,但没有人愿意花时间编写C代码只是为了让它不可移植。

This is frustrating given that the standard was written and finalized over 10 years ago now. 考虑到标准是在10年前编写并最终确定的,这是令人沮丧的。 Plus I hear discussions of a C1x from time to time, and I wonder why someone would be taking steps to revise the language given that the current version of the language isn't yet implemented. 另外,我不时听到有关C1x的讨论,我想知道为什么有人会采取措施修改语言,因为当前版本的语言还没有实现。

So my question is, as joe blow C programmer today, what is useful wrt the C99 standard to me (if any)? 所以我的问题是,作为乔今天的C程序员,我对C99标准有什么用处(如果有的话)?

C99 brings features that really makes programming in C easier and more error safe: C99带来的功能真正使C语言编程更容易,更安全:

  • designated initializers 指定的初始化者
  • compound literals 复合文字
  • for -scope variables for -scope变量
  • fixed width integer types 固定宽度整数类型

The language is also much more expressive with 这种语言也更具表现力

  • variadic macros 可变宏
  • inline functions inline函数

On my linux machine I have four compilers that support C99 to a satisfying extent that make this usable on a daily base: gcc , clang , opencc and icc . 在我的linux机器上,我有四个支持C99的编译器达到令人满意的程度,使其可以在日常基础上使用: gccclangopenccicc

The first two are open source compilers where clang trying to be code compatible to gcc (meaning C99 support is about the same). 前两个是开源编译器,其中clang试图与gcc代码兼容(意味着C99支持大致相同)。

The later two are from the two major CPU producers and are commercial but with generous license policy for non commercial users. 后两者来自两个主要的CPU生产商,并且是商业性的,但对非商业用户有慷慨的许可政策。 Their C99 is a bit less, in particular their support for inline seems not completely consistent with the standard, yet. 他们的C99有点少,特别是他们inline的支持似乎与标准不完全一致。

MSVC does not, nor will it probably ever, support C99. MSVC不会,也不会支持C99。 But Microsoft has little incentive to update their C compiler. 但微软几乎没有动力更新他们的C编译器。 It's not like they will lose much business over it. 这并不是说他们会失去太多的业务。

But there are plenty of compilers that have support for C99. 但是有很多编译器都支持C99。

http://en.wikipedia.org/wiki/C99#Implementations http://en.wikipedia.org/wiki/C99#Implementations

Regarding gcc: 关于gcc:

http://gcc.gnu.org/c99status.html http://gcc.gnu.org/c99status.html

You are right that perhaps C99 is not useful for library code (and may never be without Microsoft's support), but if you're working on an in-house or personal project where you can pick the compilers and tools, then the portability is not much of an issue. 你是对的,或许C99对于库代码没有用(并且可能永远不会没有微软的支持),但如果你正在从事内部或个人项目,你可以选择编译器和工具,那么可移植性不是很多问题。

Regarding C1x, I think it's worth noting that the standards committee is well aware that C99 has not been widely adopted and doesn't want to repeat the same mistakes (or to make the situation worse). 关于C1x,我认为值得注意的是,标准委员会非常清楚C99尚未被广泛采用,并且不想重复相同的错误(或使情况更糟)。 From the C1x charter : 来自C1x章程

Unlike for C9X, the consensus at the London meeting was that there should be no invention, without exception. 与C9X不同,伦敦会议的共识是没有任何发明,毫无例外。 Only those features that have a history and are in common use by a commercial implementation should be considered. 只应考虑那些具有历史并且通过商业实现共同使用的功能。 Also there must be care to standardize these features in a way that would make the Standard and the commercial implementation compatible. 此外,必须注意以一种使标准和商业实现兼容的方式标准化这些功能。

And: 和:

The original standard had a very positive reception from both the user and vendor communities. 原始标准得到了用户和供应商社区的积极响应。 However, C99 has been not so widely received. 但是,C99并没有得到如此广泛的接受。

You should use C99 whenever you are not locked in an environment that doesn't support C99 (embeded systems most notably). 每当您没有锁定在不支持C99的环境中时(尤其是嵌入式系统),您应该使用C99。

And yes, if you know that your library will be used by people that are using MSVC, you can't use C99 features in the interfaces, but there is no reason not to use C99 in the implementation (apart from library feature dependencies of course). 是的,如果您知道您的库将被使用MSVC的人使用,您不能在接口中使用C99功能,但没有理由不在实现中使用C99(当然除了库功能依赖性之外) )。

Original answer: "Uh? What compilers don't support C99? Plus when you move from compilers to tools, C99 is actually more commonly supported then C89." 原始答案:“呃?哪些编译器不支持C99?当你从编译器转到工具时,C99实际上比C89更受支持。”

如果你关心表现,就没有办法restrict

FreeBSD现在使用Clang进行内核编译,而且非常支持C99。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM