我使用restrict限定符时出错

sap*_*Pro 5 c pointers restrict-qualifier

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

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)
Run Code Online (Sandbox Code Playgroud)
#include <stdio.h>

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);
}
Run Code Online (Sandbox Code Playgroud)

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

sje*_*397 5

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

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

这里