2

I have an array declared in my main function: float A[n][n];

My goal is to pass it to a function with the restrict keyword: void func(int n, float restrict A[][n])

I tried the syntax above, but I am not getting the optimization in running time that I am expecting. I have also seen this syntax for 1d arrays: void func(int n, float A[restrict])

grace9
  • 47
  • 6
  • There need not be any change in running time. Why'd you expect there to be any? – Antti Haapala -- Слава Україні Feb 15 '20 at 21:06
  • I expected there to be a reduction in running time because I read that the compiler performs extra checks for pointer aliasing including array references in function parameters. By telling the compiler not to do these checks, I expected a reduction in running time. – grace9 Feb 15 '20 at 21:16
  • 1
    You have only *one* pointer argument. The restrict means that it cannot point to any other `float` *array* that you could use within the function, or that any other outer *float pointer* that you use cannot point to an array element. If there are not even such pointers being used there cannot conceivably be any optimization effects. – Antti Haapala -- Слава Україні Feb 15 '20 at 21:24
  • Thank you. But I actually have two more float arrays being passed to func, so I think it may apply here. – grace9 Feb 15 '20 at 21:28

1 Answers1

4

The pointer can be restrict. All below forms are equivalent:

void func(int n, float A[restrict n][n]);
void func(int n, float A[restrict][n]);
void func(int n, float (* restrict A)[n]);
KamilCuk
  • 120,984
  • 8
  • 59
  • 111