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
1
vote
0 answers

What are the differences between restrict, __restrict, and _restrict_ keywords in C++?

There are three entities named around restrict for which I wonder if there is any clear or subtle distinction: restrict (type qualifier in C) __restrict__ (GCC) __restrict (MSVC) Are these entities virtually always interchangeable in terms of…
Herpes Free Engineer
  • 2,425
  • 2
  • 27
  • 34
1
vote
3 answers

Why is the __restrict__ modifier not enforced?

If a function parameter is annotated const int &x and I try to do x++ in the function body, I get a compile time error for modifying a read-only reference. But if I use the __restrict__ modifier like so: void foo(int & __restrict__ a, int &…
springworks00
  • 104
  • 15
1
vote
1 answer

Restriction on child pointer of a restricted pointer?

The article mentions: Restricted pointers can be copied from one to another to create a hierarchy of pointers. However there is one limitation defined in the C99 standard. The child pointer must not be in the same block-level scope as the parent…
HCSF
  • 2,387
  • 1
  • 14
  • 40
1
vote
1 answer

Why is the format in printf_s (Annex K) marked as restrict?

I am fully aware of the existence of this question. However, printf_s considers presence of specifier %n as an error, thus no write operation to format would ever be expected from printf_s. What sense does restrict make here?
iDingDong
  • 447
  • 2
  • 11
1
vote
1 answer

Either equal or not overlapped

Let's say a function that add two vectors void add256(int* r, int* p, int* q) { for (int i=0; i<256; ++i) { r[i] = p[i] + q[i]; } } Now if I know r is either p or not in the same array with p, and same to q, can restrict help…
l4m2
  • 1,157
  • 5
  • 17
1
vote
1 answer

Combining __restrict__ and __attribute__((aligned(32)))

I want to ensure that gcc knows: The pointers refer to non-overlapping chunks of memory The pointers have 32 byte alignments Is the following the correct? template void f(const T* __restrict__ __attribute__((aligned(32)))…
hamster on wheels
  • 2,771
  • 17
  • 50
1
vote
3 answers

C restrict with typedef

i'm doing some code now and got some problem using restrict keyword. typedef int* pt; int foo(pt a, pt b) { ... /* stuff */ } What if I want to make a and b restricted? The code below failed: typedef int* pt; int foo(pt restrict a, pt restrict…
pudiva
  • 274
  • 5
  • 15
1
vote
3 answers

Why does the restrict qualifier still allow memcpy to access overlapping memory?

I wanted to see if restrict would prevent memcpy from accessing overlapping memory. The memcpy function copies n bytes from memory area src to memory area dest directly. The memory areas should not overlap. memmove uses a buffer so there is no risk…
Duy Đặng
  • 409
  • 1
  • 7
  • 15
1
vote
1 answer

restrict-Keyword not working?

I'm using mingw32-gcc, with the C99 standard. I pasted below code with a few edits from an article about the restrict keyword - http://wr.informatik.uni-hamburg.de/_media/teaching/wintersemester_2013_2014/epc-1314-fasselt-c-keywords-report.pdf.…
Nathan Schmidt
  • 374
  • 1
  • 4
  • 16
1
vote
2 answers

Can I `__restrict__ this` somehow?

I've been watching Mike Acton's talk on Data-oriented design in C++ in CppCon 2014, and he gives this example: int Foo::Bar(int count) { int value = 0; for (int i = 0; i < count; i++) { if (m_someDataMemberOfFoo) value++ } …
einpoklum
  • 118,144
  • 57
  • 340
  • 684
1
vote
2 answers

Behaviour of restrict keyword inside structs

The scenario: Suppose I have a struct type holding a bunch of pointers, all of which declared restrict, and a function which takes a couple of these struct as argument as follows: struct bunch_of_ptr { double *restrict ptr00; double…
Saran Tunyasuvunakool
  • 1,064
  • 1
  • 9
  • 23
1
vote
1 answer

restrict for return type and local variables

I have a good understanding of when to use restrict for function arguments. But all the articles I've found so far never mention other declarations (like function return values and local variables). Here is one example: extern int…
martinkunev
  • 1,364
  • 18
  • 39
1
vote
3 answers

Can I use restrict qualifier in this function?

I read the standard but still cannot be sure: #include #include void repl(char *restrict ap){ char *cp=strchr(ap,(int)'m'); *cp='M'; } int main(){ char arr[] = "example"; repl(arr); puts(arr); return…
cshu
  • 5,654
  • 28
  • 44
1
vote
1 answer

Building an R package with Rcpp which contains C source and header with restrict qualifier?

I have an third party source file and corresponding header (containing the declarations and include directives for GSL etc) which are written in C. I am trying to build an R package around these source files, basically making a wrappers for the…
Jouni Helske
  • 6,427
  • 29
  • 52
1
vote
1 answer

Get rid of "type qualifier" warnings on functions using the restrict keyword

I'm trying to clean up warnings that I'm getting when compiling Blitz++ of the form: /opt/local/include/blitz/tinyvec2.h:261:35: warning: type qualifiers ignored on function return type…
Dave
  • 7,555
  • 8
  • 46
  • 88
1 2 3
8 9