我使用restrict限定符时出错

当我编译以下程序时,我得到错误:

gcc tester.c -o tester tester.c: In function 'main': tester.c:7:17: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'ptr_X' tester.c:7:17: error: 'ptr_X' undeclared (first use in this function) tester.c:7:17: note: each undeclared identifier is reported only once for each function it appears in tester.c:10:17: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'ptr_Y' tester.c:10:17: error: 'ptr_Y' undeclared (first use in this function) 

 #include  int main() { int x = 10; int y = 20; int *restrict ptr_X; ptr_X = &x; int *restrict ptr_Y; ptr_Y = &y; printf("%d\n",*ptr_X); printf("%d\n",*ptr_Y); } 

为什么我会收到这些错误?

并非所有编译器都符合C99标准。 例如Microsoft的编译器,根本不支持C99标准。 如果您在x86平台上使用MSVC,则无法访问此关键优化选项。

使用GCC时,请记住通过在编译标志中添加-std = c99来启用C99标准。 在无法使用C99编译的代码中,使用__restrict__restrict__将关键字作为GCC扩展名启用。

从这里开始 。

Restrict是C99的一部分,因此您必须通过为gcc指定-std=c99标志将其编译为C99程序。

 gcc -std=c99 tester.c -o tester