A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

  • Index
  • » C
  • » restrict keyword in C99

#1 2012-02-15 08:01 AM

Registered: 2011-10-10
Posts: 32

restrict keyword in C99


Can any one tell me the use of restrict keyword in C and concept of pointer aliasing
in simple words. I checked several links but could not understand exactly.



#2 2012-02-15 02:00 PM

From: Boston, MA
Registered: 2002-06-12
Posts: 3,844

Re: restrict keyword in C99

I don't think I can do a better job explaining it than this Wikipedia page...  But, in short: it's purely a feature to help compiler optimization...  Pointer aliasing is just when there are multiple pointers into the same memory location...  Ie: there are multiple "aliases" by which you can reach the same memory...  If that's the case, then the compiler can't be as aggressive with its optimizations in certain cases (like the contrived example on the Wiki page)...  But, by marking all pointers being dealt with with "restrict", you are essentially telling that compiler that you promise to only pass in distinct pointers that don't overlap each other, so it can go ahead and optimize under that assumption...  If you break that promise and pass in overlapping pointers, then things may not work as expected anymore, since the compiler is no longer being as careful about such possibilities anymore...


  • Index
  • » C
  • » restrict keyword in C99

Board footer

Powered by FluxBB