简体   繁体   English

C ++ 11是否添加了C99限制说明符? 如果没有,为什么不呢?

[英]Does C++11 add the C99 restrict specifier? If not, why not?

restrict is a C99 feature which is getting a lot of attention lately by allowing the compiler to perform "previously-fortran-only" optimizations to pointers. restrict是一个C99功能,它最近得到了很多关注,允许编译器对指针执行“以前只能进行Fortran”优化。 It's also the same keyword announced by Microsoft recently to be the underpinnings of the C++AMP specification. 这也是微软最近公布的相同关键词,它是C ++ AMP规范的基础。

Is that keyword actually in the FCD? 该关键字实际上是在FCD中吗? If not, is there a specific reason it was omitted? 如果没有,是否有特定原因被省略?

The only mention of restrict in the C++11 FDIS is on §17.2 [library.c]: 在C ++ 11 FDIS中唯一提到的restrict是在§17.2[library.c]上:

The descriptions of many library functions rely on the C standard library for the signatures and semantics of those functions. 许多库函数的描述依赖于C标准库来获取这些函数的签名和语义。 In all such cases, any use of the restrict qualifier shall be omitted. 在所有这些情况下,应省略对restrict任何使用。

So restrict is not in C++11. 所以restrict不在C ++ 11中。

One argument is that C needs restrict more than C++, because many operations are done with pointers to primitive types and therefore C code has more aliasing problems than C++. 一个论点是C需要比C ++更多的restrict ,因为许多操作是使用指向原始类型的指针完成的,因此C代码比C ++有更多的别名问题。

The aliasing rules say that pointers to different types cannot alias, so if the parameters to a function are of different class types they just cannot overlap. 别名规则说指向不同类型的指针不能别名,因此如果函数的参数具有不同的类类型,则它们不能重叠。

In C++ we also have the valarray family of classes that are supposed to handle arrays of primitive types that are not allowed to alias. 在C ++中,我们还有valarray类,它们应该处理不允许别名的基本类型数组。 Not that it is used much... 不是说它用得太多了......

Adding yet another way to resolve some aliasing problems, obviously didn't excite the committee enough. 添加另一种方法来解决一些别名问题,显然并没有让委员会充分兴奋。

http://herbsutter.com/2012/05/03/reader-qa-what-about-vc-and-c99/ http://herbsutter.com/2012/05/03/reader-qa-what-about-vc-and-c99/

Not only the VC++ team, but also the ISO C++ standards committee, considered adding restrict to VC++ and ISO C++, respectively. 不仅VC ++团队,而且ISO C ++标准委员会,分别考虑增加对VC ++和ISO C ++的限制。 Although it was specifically suggested for ISO C++11, it was rejected, in part because it's not always obvious how it extends to C++ code because C++ is a larger language with more options and we would want to make sure the feature works correctly across the entire language. 虽然它是专门为ISO C ++ 11建议的,但它被拒绝了,部分原因是它并不总是很明显它是如何扩展到C ++代码的,因为C ++是一种更大的语言,有更多选项,我们希望确保该功能在整个语言。

Don't think it's in C++1x (unfortunately time has long run out for 0x...!) but at least msvc and g++ support it through __restrict and __restrict__ extensions. 不要认为它是在C ++ 1x中(遗憾的是时间已经耗尽了0x ......!)但至少msvc和g ++通过__restrict__restrict__扩展支持它。 (I don't use gcc much, I think that's the correct extension). (我不使用gcc,我认为这是正确的扩展)。

To work properly with C++ I feel that we would also need restricted references, not just pointers, maybe along the lines of my question C++ aliasing rules . 为了正常使用C ++,我觉得我们还需要有限的引用,而不仅仅是指针,可能与我的问题C ++别名规则一致 Not sure if some of these considerations might be holding things up... 不确定这些考虑因素是否可能会阻碍......

I will take a crack at "why not?" 我会抓住“为什么不呢?”

restrict is basically just an assertion that the compiler cannot verify. restrict基本上只是编译器无法验证的断言。 (Or more precisely, when the compiler can verify it, the assertion itself is not helpful.) This is just not the sort of thing that the C++ committee is going to like. (或者更准确地说,当编译器可以验证它时,断言本身没有帮助。)这不是C ++委员会喜欢的那种东西。 C++ has always tended to assume "sufficiently smart compilers"; C ++总是倾向于假设“足够聪明的编译器”; heck, look at the hideous performance of the most trivial C++ libraries before the compilers caught up. 哎呀,看看编译器赶上之前最琐碎的C ++库的糟糕表现。

I also suspect the committee felt that defining restrict semantics precisely in the presence of all the other C++ features (references, rvalue references, blah blah blah) would be non-trivial. 我还怀疑委员会认为,在存在所有其他C ++特性(引用,右值引用,等等等等)的情况下定义restrict语义将是非平凡的。

So, non-trivial to specify + "a sufficiently smart compiler doesn't need it" = NAK. 因此,指定+“足够智能的编译器并不需要它”非常重要= NAK。

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

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