gpt4 book ai didi

c++ - 为什么限制关键字不是 C++ 的一部分?

转载 作者:IT老高 更新时间:2023-10-28 12:51:51 25 4
gpt4 key购买 nike

标题说明了一切。我很好奇为什么限制关键字不是 C++ 的一部分?我对 C++ 了解不多,而且我仍然无法在网上找到任何可以阻止它的理由。如果 C++ 标准会像 C 那样使用这个关键字,有谁知道会发生什么可怕的事情?是不是根本不需要?

更多解释:这不是关于使用它,也许我这辈子都不会从这个关键字中受益。这个问题只是关于好奇心,因为从 C99 开始,restrict 是 C 的一部分,也就是 15 年。

请阅读以下内容:我对技术原因感兴趣,而不是像“他们只是不喜欢,这还不够酷”之类的意见

最佳答案

在 C++ 中定义“限制”有几个问题,其中一些在 WG 论文 N3635 中列出:http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3635.pdf “向 C++ 的类限制语义发展”

Some possible issues with restrict in C++ are:

  • Restrict Class members and indirection with “this pointer”
  • Passing of restrict qualifiers into functions, functors, lambdas, and templates
  • Escaping of restrict pointer values inside functions
  • Overlapping array members, strides

文档还列出了几个 C++ 编译器,它们对 C++ 的“限制”支持有限。

在 N3635 中也有关于不包含限制到 C++ 的有趣历史记录:

At the time of reviewing C99 feature inclusion in C++ during the Mont Tremblant meeting, restrict was considered but was waiting a paper proposal although none came forward....

Restrict is a C99 feature and was never designed to work in class abstractions and it may have to do with that pointers are not common in C++. ... it was designed for fine-grain aliasing for C, but not well-designed for type-based aliasing in C++

关于c++ - 为什么限制关键字不是 C++ 的一部分?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22724980/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com