Questions tagged [restrict-qualifier]

Restrict is a keyword that could applied to a pointer to an object. It makes this pointer the one and only way to access the data of that object.

The restrict-qualifier tells the compiler that if the memory accessed by the restrict-qualified pointer is modified, no other pointers will access it.

The compiler may use this hint to optimize the restrict-qualified pointers in such a way, that would otherwise cause incorrect or undefined behavior.

C++ supports restrict keyword for compatibility with C. However, a C++ compiler will ignore the restrict keyword, because in C++ "restrict" is a valid variable name. C++ compilers, though, have a special __restrict__ qualifier.

In-detail information along with examples can be found on the IBM website.

128 questions
0
votes
0 answers

C++: Bypassing strict-aliasing through union, then use __restrict extension

I wonder if it is possible to tailor strict aliasing requirements to specifically designed cases, while still preserving strict aliasing in general or -O2/-O3 optimization respectively. To be more precise, in cases where it is needed, strict…
rsp1984
  • 1,877
  • 21
  • 23
0
votes
4 answers

Why compiler don't generate a warning or error if some restrict pointers point to the same object?

If we have a function: void func(int *restrict a, int *restrict b, int *restrict c) { *c = *a + *b; } In principle, this code may lead to some error: int aa = 1; func(&aa, &aa, &aa); because in func, *a *b *c will be the same object. But why…
Yishu Fang
  • 9,448
  • 21
  • 65
  • 102
0
votes
1 answer

Why can I modify a const __restrict pointer but not a typdef'd version?

Note: I'm using the objective C compiler that ships with the latest version of Xcode. Why is it that this is legal: void verySpecial(const float* __restrict foo, const int size) { for (int i = 0; i < size; ++i) { // ... do special…
i_am_jorf
  • 53,608
  • 15
  • 131
  • 222
0
votes
2 answers

Compiler error involving restrict keyword

Possible Duplicate: What does the restrict keyword mean in C++? I'm trying to install QMCPACK on OS X 10.8.2 and I'm getting a lot of errors like this: bspline_base.h:95:17: error: expected ';' at end of declaration list void *restrict coefs; …
Nick
  • 5,228
  • 9
  • 40
  • 69
0
votes
1 answer

Does the __restrict allow to ignore the strict aliasing rule?

Let's say that I have a buffer of chars and I want to avoid using memcpy, and access to it through an int* variable: char buffer[100]; strcpy(buffer,"Hello"); int* __restrict ptr=(int*)buffer; *ptr= 97; printf("%s",buffer); Now this of course…
Ramy Al Zuhouri
  • 21,580
  • 26
  • 105
  • 187
0
votes
1 answer

Is it dangerous to call a function and pass it a restrict-qualified pointer?

Consider these two functions: void foo(char * __restrict localPtr) { // some work with localPtr } void bar(char * __restrict ptr) { // some work with ptr foo(_ptr); // some other work with ptr } As ptr has been declared __restrict…
qdii
  • 12,505
  • 10
  • 59
  • 116
0
votes
1 answer

Does clang++ support __restrict?

The following code compiles with g++ 4.7.1 but not clang 3.1 struct A { int foo(); }; int A::foo() __restrict { return 0; } int main(int argc, char * argv[]) { A a; return a.foo(); } Does clang support __restrict? or is it using a…
qdii
  • 12,505
  • 10
  • 59
  • 116
0
votes
1 answer

OpenMP with restrict pointers fails with ICC while GCC/G++ succeeds

I implemented a simple matrix vector multiplication for sparse matrices in CRS using an implicit openMP directive in the multiplication loop. The complete code is in GitHub:…
Torbjörn
  • 5,512
  • 7
  • 46
  • 73
1 2 3
8
9