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. This allows the compiler to make optimizations (for example, vectorization) that would not otherwise have been possible.
12-577: [REDACTED] Look up restricted in Wiktionary, the free dictionary. Restricted may refer to: R rating (disambiguation) , list of subjects where "R" stands for "Restricted" 18 rating , media rating designation sometimes called "Restricted" Restricted (country club) , historical use of the term in country clubs in the United States Restricted airspace , airspace for which air traffic
24-474: Is different from Wikidata All article disambiguation pages All disambiguation pages restricted [REDACTED] Look up restricted in Wiktionary, the free dictionary. Restricted may refer to: R rating (disambiguation) , list of subjects where "R" stands for "Restricted" 18 rating , media rating designation sometimes called "Restricted" Restricted (country club) , historical use of
36-468: Is different from Wikidata All article disambiguation pages All disambiguation pages Restrict restrict limits the effects of pointer aliasing , aiding optimizations . If the declaration of intent is not followed and the object is accessed by an independent pointer, this will result in undefined behavior . If the compiler knows that there is only one pointer to a memory block, it can produce better optimized code. For instance: In
48-500: Is restricted or prohibited for safety or security concerns Restricted area , several uses Restricted free agent , a type of free agent in various professional sports Restricted list , a roster status in Major League Baseball Restricted stock , stock of a company that is not fully transferable See also [ edit ] All pages with titles beginning with restricted Restrict , keyword in
60-560: The GCC 's and Clang 's __restrict__ , and Visual C++ 's __declspec(restrict) . In addition, __restrict is supported by those three compilers. The exact interpretation of these alternative keywords vary by the compiler: To help prevent incorrect code, some compilers and other tools try to detect when overlapping arguments have been passed to functions with parameters marked restrict . The CERT C Coding Standard considers misuse of restrict and library functions marked with it (EXP43-C)
72-502: The C programming language Restriction (disambiguation) Topics referred to by the same term [REDACTED] This disambiguation page lists articles associated with the title Restricted . If an internal link led you here, you may wish to change the link to point directly to the intended article. Retrieved from " https://en.wikipedia.org/w/index.php?title=Restricted&oldid=1093035660 " Category : Disambiguation pages Hidden categories: Short description
84-502: The C programming language Restriction (disambiguation) Topics referred to by the same term [REDACTED] This disambiguation page lists articles associated with the title Restricted . If an internal link led you here, you may wish to change the link to point directly to the intended article. Retrieved from " https://en.wikipedia.org/w/index.php?title=Restricted&oldid=1093035660 " Category : Disambiguation pages Hidden categories: Short description
96-422: The above code, the pointers ptrA , ptrB , and val might refer to the same memory location , so the compiler may generate less optimal code: However, if the restrict keyword is used and the above function is declared as then the compiler is allowed to assume that ptrA , ptrB , and val point to different locations and updating the memory location referenced by one pointer will not affect
108-459: The above mini-example tends to be small, and in real-life cases large loops doing heavy memory access tends to be what is really helped by restrict. As mentioned above, how incorrect code behaves is undefined , the compiler only ensures the generated code works properly if the code follows the declaration of intent. C++ does not have standard support for restrict , but many compilers have equivalents that usually work in both C++ and C, such as
120-429: The compiler can rearrange the code more freely, the compiler can generate code that executes faster. In the second version of the above example, the store operations are all taking place after the load operations, ensuring that the processor won't have to block in the middle of the code to wait until the store operations are complete. Note that the real generated code may have different behaviors. Benefit with
132-414: The memory locations referenced by the other pointers. The programmer, not the compiler, is responsible for ensuring that the pointers do not point to identical locations. The compiler can e.g. rearrange the code, first loading all memory locations, then performing the operations before committing the results back to memory. The above assembly code is shorter because val is loaded only once. Also, since
SECTION 10
#1732852185523144-529: The term in country clubs in the United States Restricted airspace , airspace for which air traffic is restricted or prohibited for safety or security concerns Restricted area , several uses Restricted free agent , a type of free agent in various professional sports Restricted list , a roster status in Major League Baseball Restricted stock , stock of a company that is not fully transferable See also [ edit ] All pages with titles beginning with restricted Restrict , keyword in
#522477