5

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?

Mat
  • 202,337
  • 40
  • 393
  • 406
vehomzzz
  • 42,832
  • 72
  • 186
  • 216
  • It compiles for me just fine. Have you got a recent version of GCC? – Cat Plus Plus Sep 08 '09 at 18:07
  • That code compiles for me on Sun C 5.8 and GCC 3.4.6. Comeau online only complains about the unused variable declaration. Please provide more details about your environment. – Rob Kennedy Sep 08 '09 at 18:10
  • ... but Comeau was in C99 mode. When I put it in C++ mode, it complains about the same thing. – Rob Kennedy Sep 08 '09 at 18:16
  • I should have been more specific about what "the same thing" meant in my last comment. In C++ mode, Comeau says it expects a semicolon, just like Enigma's compiler. – Rob Kennedy Sep 08 '09 at 18:28
  • That's not valid C++ code therefore it wont work in C++ mode. restrict is restricted to C99. – B.S. Sep 08 '09 at 18:49
  • @Ben look more closely at my question. I specified -std=c99 for the compiler. @Rob Kennedy already provided a solution. – vehomzzz Sep 08 '09 at 18:52

1 Answers1

9

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
  • 161,384
  • 21
  • 275
  • 467
  • 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 Sep 08 '09 at 18:17
  • 5
    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 Sep 08 '09 at 18:25