Optimization[edit] If the compiler knows that there is only one pointer to a memory block, it can produce better optimized code. For instance: void updatePtrs(size_t *ptrA, size_t *ptrB, size_t *val) { *ptrA += *val; *ptrB += *val; } In the above code, the pointers ptrA, ptrB, and val might refer to the same memory location, so the compiler may generate less optimal code: load R1 ← *val ; Load the value of val pointer load R2 ← *ptrA ; Load the value of ptrA pointer add R2 += R1 ; Perform Addition set R2 → *ptrA ; Update the value of ptrA pointer load R2 ← *ptrB ; 'load' may have to wait until preceding 'set' completes load R1 ← *val ; Have to load a second time to ensure consistency add R2 += R1 set R2 → *ptrB However, if the restrict keyword is used and the above function is declared as void updatePtrs(size_t *restrict ptrA, size_t *restrict ptrB, size_t *restrict val); then the compiler is allowed to assume that ptrA, ptrB, and val point to different locations and updating one pointer will not affect 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. load R1 ← *val ; Note that val is now only loaded once load R2 ← *ptrA ; Also, all 'load's in the beginning ... load R3 ← *ptrB add R2 += R1 add R3 += R1 set R2 → *ptrA ; ... all 'set's in the end. set R3 → *ptrB The above assembly code is shorter because val is loaded only once. Also, since 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 set 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 set operations are complete.

References[edit] "ISO/IEC 9899:TC2 Committee Draft" (PDF). ISO. May 6, 2005: 108–112. Retrieved 2008-12-22.  ^ Ulrich Drepper (October 23, 2007). "Memory part 5: What programmers can do". What every programmer should know about memory. lwn.net. ...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.) 

External links[edit] Demystifying The Restrict Keyword: explanation and examples of use Walls, Douglas. "How to Use the restrict Qualifier in C". Oracle™. Retrieved 2012-11-21.  Restricted Pointers in C: the original rationale behind the definition Retrieved from "https://en.wikipedia.org/w/index.php?title=Restrict&oldid=824215403" Categories: C (programming language)

Navigation menu Personal tools Not logged inTalkContributionsCreate accountLog in Namespaces ArticleTalk Variants Views ReadEditView history More Search Navigation Main pageContentsFeatured contentCurrent eventsRandom articleDonate to WikipediaWikipedia store Interaction HelpAbout WikipediaCommunity portalRecent changesContact page Tools What links hereRelated changesUpload fileSpecial pagesPermanent linkPage informationWikidata itemCite this page Print/export Create a bookDownload as PDFPrintable version Languages FrançaisРусский Edit links This page was last edited on 6 February 2018, at 00:41. Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Terms of Use and Privacy Policy. Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc., a non-profit organization. Privacy policy About Wikipedia Disclaimers Contact Wikipedia Developers Cookie statement Mobile view (window.RLQ=window.RLQ||[]).push(function(){mw.config.set({"wgPageParseReport":{"limitreport":{"cputime":"0.080","walltime":"0.421","ppvisitednodes":{"value":234,"limit":1000000},"ppgeneratednodes":{"value":0,"limit":1500000},"postexpandincludesize":{"value":6097,"limit":2097152},"templateargumentsize":{"value":83,"limit":2097152},"expansiondepth":{"value":7,"limit":40},"expensivefunctioncount":{"value":0,"limit":500},"entityaccesscount":{"value":0,"limit":400},"timingprofile":["100.00% 409.880 1 -total"," 9.83% 40.301 1 Template:Cite_paper"," 7.48% 30.675 1 Template:About"," 3.20% 13.109 1 Template:Reflist"," 1.91% 7.816 2 Template:Cite_web"," 0.51% 2.101 1 Template:Code"," 0.51% 2.094 1 Template:Lowercase_title"," 0.36% 1.477 1 Template:Main_other"]},"scribunto":{"limitreport-timeusage":{"value":"0.037","limit":"10.000"},"limitreport-memusage":{"value":1944399,"limit":52428800}},"cachereport":{"origin":"mw1326","timestamp":"20180217153354","ttl":1900800,"transientcontent":false}}});});(window.RLQ=window.RLQ||[]).push(function(){mw.config.set({"wgBackendResponseTime":514,"wgHostname":"mw1326"});});

Restrict - Photos and All Basic Informations

Restrict More Links

Restriction (disambiguation)C Programming LanguageC99Keyword (computer Programming)Pointer (computer Programming)CompilerPointer AliasingOptimizing CompilerUndefined BehaviorFortranC++GNU Compiler CollectionClangVisual C++Pointer AliasingInternational Organization For StandardizationLwn.netHelp:CategoryCategory:C (programming Language)Discussion About Edits From This IP Address [n]A List Of Edits Made From This IP Address [y]View The Content Page [c]Discussion About The Content Page [t]Edit This Page [e]Visit The Main Page [z]Guides To Browsing WikipediaFeatured Content – The Best Of WikipediaFind Background Information On Current EventsLoad A Random Article [x]Guidance On How To Use And Edit WikipediaFind Out About WikipediaAbout The Project, What You Can Do, Where To Find ThingsA List Of Recent Changes In The Wiki [r]List Of All English Wikipedia Pages Containing Links To This Page [j]Recent Changes In Pages Linked From This Page [k]Upload Files [u]A List Of All Special Pages [q]Wikipedia:AboutWikipedia:General Disclaimer

view link view link view link view link view link