views:

301

answers:

1

In the following example:

void foo (double *ptr)
{
     const double * restrict  const restr_ptr=ptr;
}

I get this error:

error: expected a ";"      const double * restrict  const restr_ptr=ptr;
                                                      ^

I compile with -std=c99, using gcc 3.4

Any Ideas?

+6  A: 

In C++, restrict is not a keyword (except for Microsoft extensions). It doesn't mean what it does in C. It looks as though you tried to apply C99 mode to your C++ compiler. Use a C compiler to compile C code, and use a C++ compiler to compile C++. Neither language is a subset of the other.

Rob Kennedy
Agh, that explain. I cannot compile using C compiler as I use C++ features where restrict is used. What's the workaround, if any?
vehomzzz
Try `__restrict`. Looks like it's a GCC extension as well as a Microsoft extension. Consider abstracting it with a macro so non-GCC, non-MS compilers don't choke on it.
Rob Kennedy
__restrict did the trick.. thanks
vehomzzz