Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • December 03, 2016, 10:05:41 PM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: what is __restrict keyword in c?  (Read 9708 times)

megatron

  • Participant
  • Joined in 2008
  • *
  • default avatar
  • Posts: 23
    • View Profile
    • Donate to Member
what is __restrict keyword in c?
« on: January 23, 2009, 12:55:23 PM »
what is __restrict keyword in c?

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,277
    • View Profile
    • Miles Ahead Software
    • Donate to Member
Re: what is __restrict keyword in c?
« Reply #1 on: January 23, 2009, 01:36:20 PM »
Looks like it's an MS specific modifier.  I just read the entry on MS site for it here:
http://msdn.microsof...5ft82fed(VS.80).aspx

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

Ehtyar

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 1,237
    • View Profile
    • Donate to Member
Re: what is __restrict keyword in c?
« Reply #2 on: January 23, 2009, 01:48:37 PM »
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.
« Last Edit: January 23, 2009, 01:55:43 PM by Ehtyar »

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,277
    • View Profile
    • Miles Ahead Software
    • Donate to Member
Re: what is __restrict keyword in c?
« Reply #3 on: January 23, 2009, 05:09:18 PM »
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) :)
« Last Edit: January 23, 2009, 05:34:22 PM by MilesAhead »

megatron

  • Participant
  • Joined in 2008
  • *
  • default avatar
  • Posts: 23
    • View Profile
    • Donate to Member
Re: what is __restrict keyword in c?
« Reply #4 on: January 25, 2009, 02:24:37 PM »
I was surprised to find a rather detailed article demonstrating the use of __restricted here.

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