What I want to convey to the compiler is that the pointers ptrs[i] are not aliases of each other and that the arrays ptrs[i] do not overlap. How shall I do this ? My ulterior motive is to encourage automatic vectorization.

Also, is there a way to get the same effect as __restrict__ on an iterator of a std::vector ?

Important note: The C++ standard does NOT support the restrict qualifier from C99 -- its not even a keyword. So any use of restrict in a C++ program is relying on an implementation extension
–
Chris DoddAug 2 '12 at 20:25

3 Answers
3

restrict, unlike the more common const, is a property of the pointer rather than the data pointed to. It therefore belongs on the right side of the '*' declarator-modifier. [] in a parameter declaration is another way to write *. Putting these things together, you should be able to get the effect you want with this function prototype:

Unless I'm mistaken, one of those "restrict" declarations is superfluous; there are no other "int **"-type variables around with which aliasing could occur. "int * restrict * ptrs" should do the job. And I wonder if "int * restrict ptrs[]" might do it also...
–
davmacSep 7 '11 at 4:27

IMHO both restricts are necessary, since other pointers might otherwise exist outside of the scope of foo.
–
Johan BezemNov 5 '11 at 16:40

"What I want to convey to the compiler is that the pointers ... are not aliases of each other"
–
davmacMar 15 '12 at 17:45

Also, late comment, but semantics of pointers "outside of the scope of foo" are not affected by restrict qualifiers on parameters of foo. The second restrict is NOT necessary.
–
davmacApr 25 '14 at 8:19