ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Other Software > Developer's Corner

what is __restrict keyword in c?

(1/1)

megatron:
what is __restrict keyword in c?

MilesAhead:
Looks like it's an MS specific modifier.  I just read the entry on MS site for it here:
http://msdn.microsoft.com/en-us/library/5ft82fed(VS.80).aspx

and I'm still not sure what it does.  :)

Ehtyar:
Basically, it informs the compiler that there are no other variables in the current function that point to the same data as your __restricted variable. It's used to manually prevent the compiler from having the CPU write data to memory, and then try to read it back again too soon, in which case the CPU will stall for a rather large number of cycles because there wasn't enough time to get the data all the way to main memory before the CPU tried to pull it back again. It is not an MS-specific extension.

I was surprised to find a rather detailed article demonstrating the use of __restricted here.

Hope this helps, Ehtyar.

MilesAhead:
I think you'll find when Microsoft adds its own wrinkle it precedes it with double underscores.  If you are using MS compilers it's always a good idea to check their documention.  A good example is try  exception handling in C++.  There's the C++ exception mechanism using try..catch, then there's MS home grown Structured Exception Handling that uses __try ..except instead of try.  They are not the same.

In this case it may just be using C 'restrict' keyword in C++ as __restrict but I wouldn't take anything for granted.

Here's a simple explanation more succinct than on MS page I think:
http://www.devx.com/tips/Tip/13825

(for some reason we all want to put the 'ed' on the end of restrict to get restricted.  I just did it too) :)

megatron:
I was surprised to find a rather detailed article demonstrating the use of __restricted here.
-Ehtyar (January 23, 2009, 01:48 PM)
--- End quote ---

Very informative link… I think I got what this keyword does…

Navigation

[0] Message Index

Go to full version