Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is the restrict keyword not part of C++?

The title says it all. I am curious why is the restrict keyword not part of C++ ? I don't know much about C++, and I'm still not able to find anything online that would give a reason blocking this. Does anyone know what terrible things would happen, if a C++ standard would use this keyword similarly to the way C does? Is it just not needed at all?

More explanation: It is not about using it, perhaps I will not have any benefit from this keyword in my whole life. This question is only about curiosity, since restrict is part of C since C99, that is 15 years.

Read this as well: I'm interested in technical reasons, not opinions like "They just didn't like, it is not cool enough"

like image 777
Gábor Buella Avatar asked Mar 28 '14 23:03

Gábor Buella


People also ask

Is restrict a keyword in C?

In the C programming language (after 99 standard), a new keyword is introduced known as restrict. restrict keyword is mainly used in pointer declarations as a type qualifier for pointers. It doesn't add any new functionality. It is only a way for programmer to inform about an optimization that compiler can make.

What is restrict type in C?

In the C programming language, restrict is a keyword, introduced by the C99 standard, that can be used in pointer declarations. By adding this type qualifier, a programmer hints to the compiler that for the lifetime of the pointer, no other pointer will be used to access the object to which it points.

Is restrict in C++?

restrict is a keyword in the C99 version of C language and not in C++. In C, A restrict-qualified pointer (or reference) is basically a promise to the compiler that for the scope of the pointer, the target of the pointer will only be accessed through that pointer (and pointers copied from it).


1 Answers

There are several issues in defining "restrict" in C++, some of them are listed in WG paper N3635: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3635.pdf "Towards restrict-like semantics for 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

Document also list several C++ compilers with limited "restrict" support for C++.

There is also interesting history note in N3635 about non-inclusion of restrict to 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++

like image 135
osgx Avatar answered Oct 08 '22 15:10

osgx