In the program I am coding, one of my function declarations goes like this:
bool parse( const sentence & __restrict sentence )
{
// whatever
}
When I compile the code with Microsoft Visual Studio 2010 Express, the compiler complains:
warning C4227: anachronism used : qualifiers on reference are ignored
However, this page of GCC’s documentation says:
In addition to allowing restricted pointers, you can specify restricted references, which indicate that the reference is not aliased in the local context.
And the same page gives a very explicit example:
void fn (int *__restrict__ rptr, int &__restrict__ rref)
{
/* ... */
}
Did I misunderstand MVSC’s warning? or should I transform all my references into pointers so that __restrict
applies?
C++ has no notion of restrict
in the way C99 does.
However, several compiler vendors offer extensions to their C++ compilers, which they call __restrict
(note the reserved name!). Given that those are extensions, their behaviour is determined by the compiler vendor. You will have to read the documentation and find out what this extension does in each compiler separately.
Just because two vendors chose the same name doesn't mean the extensions have anything in common.
Presumably since it starts with __
__restrict
is an implementation-specific extension that can behave as each implementation desires. I imagine both compilers are correct in this case.
Instead of changing your references to pointers, why not avoid restrict
entirely, instead using a profiler to find your hot spots, and only if it shows that such aliasing not covered by the C++ strict-alias rules is taking significant CPU time would I consider changing one specific reference to a pointer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With