Jump to content
  • Advertisement
Sign in to follow this  
discman1028

__restrict on references

This topic is 3645 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
References can't be reseated, and a reference can't refer to an "array" of subsequent values in memory, like a pointer can point at, so a lot more is known about their aliasing.

Share this post


Link to post
Share on other sites
Quote:
Original post by Zahlman
References can't be reseated...


This compiles OK in VS2005... is this behavior MS-specific?



class foo
{
public:
int a;
};

int main()
{
foo f1;
foo f2;
foo& r = f1;
r = f2;
...
}





Share this post


Link to post
Share on other sites
Quote:
Original post by discman1028
Quote:
Original post by Zahlman
References can't be reseated...


This compiles OK in VS2005... is this behavior MS-specific?


*** Source Snippet Removed ***


That reference isn't being re-seated. You're simply copying the object via the copy assignment operator.

For illustration, here is equivalent code using pointers instead of references:


class foo
{
public:
int a;

void operator=(const foo& rhs)
{
std::cout << "Assignment Operator" << std::endl;
}
};

int main()
{
foo f1;
foo f2;
foo* r = &f1;
(*r) = f2;
}

Share this post


Link to post
Share on other sites
Quote:
Original post by fpsgamer

That reference isn't being re-seated. You're simply copying the object via the copy assignment operator.


Ah yeah... oops. :)

Anyhow, more quibble:

Quote:
Original post by Zahlman
...a reference can't refer to an "array" of subsequent values in memory...


But a reference can be passed into a function, making it a "black box" as far as the function is concerned (unless alias analysis goes beyond function scope, which it could but I doubt most compilers do).

Plus, an object offset into an array such as "objArray[counter]" can be seated to a reference, in which case no more is known about their aliasing than a pointer that steps along an array.

Plus, a pointer (as opposed to a second reference) could be pointing to the same memory the reference is referencing.

3 reasons for __restrict for references... right?

Share this post


Link to post
Share on other sites
Unless, as I mentioned earlier, references have an implicit "restrict" behavior, in which case none of the above three present an issue...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!