Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

errors as i use the restrict qualifier

When I compile the following program I get errors :

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 <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);
}

Why am I getting these errors ?

like image 263
saplingPro Avatar asked Oct 31 '12 09:10

saplingPro


1 Answers

Not all compilers are compliant with the C99 standard. For example Microsoft's compiler, does not support the C99 standard at all. If you are using MSVC on a x86 platform you will not have access to this critical optimization option.

When using GCC, remember to enable the C99 standard by adding -std=c99 to your compilation flags. In code that cannot be compiled with C99, use either __restrict or __restrict__ to enable the keyword as a GCC extension.

From here.

like image 122
sje397 Avatar answered Sep 22 '22 09:09

sje397