Content deleted Content added
small, clarifying edition dcdf |
→top: A small cleanup |
||
Line 4:
In the [[C programming language]], as of the [[C99|C99 standard]], <code>restrict</code> is a [[Keyword (computer programming)|keyword]] that can be used in [[Pointer (computer programming)|pointer]] declarations. The <code>restrict</code> keyword is a declaration of intent given by the programmer to the [[compiler]]. It says that for the lifetime of the pointer, only it or a value directly derived from it (such as {{code|pointer + 1}}) will be used to access the object to which it points. This limits the effects of [[pointer aliasing]], aiding [[Optimizing compiler|optimizations]]. If the declaration of intent is not followed and the object is accessed by an independent pointer, this will result in [[undefined behavior]]. The use of the <code>restrict</code> keyword in C, in principle, allows non-obtuse C to achieve the same performance as the same program written in [[Fortran]].<ref name=drepper>{{cite web|url=https://lwn.net/Articles/255364/|title=Memory part 5: What programmers can do|work=What every programmer should know about memory|author=[[Ulrich Drepper]]|date=October 23, 2007|publisher=[[lwn.net]]|quote="...The default aliasing rules of the C and C++ languages do not help the compiler making these decisions (unless restrict is used, all pointer accesses are potential sources of aliasing). This is why Fortran is still a preferred language for numeric programming: it makes writing fast code easier. (In theory the restrict keyword introduced into the C language in the 1999 revision should solve the problem. Compilers have not caught up yet, though. The reason is mainly that too much incorrect code exists which would mislead the compiler and cause it to generate incorrect object code.)"}}</ref>
[[C++]] does not have standard support for <code>restrict</code>, but many compilers have equivalents
== Optimization ==
|