Do not use! This tag has multiple meanings depending context. If you are looking for the restrict keyword in C-like languages use [restrict-qualifier] instead.
Questions tagged [restrict]
353 questions
47
votes
3 answers
Why is the restrict keyword not part of C++?
The title says it all. I am curious why is the restrict keyword not part of C++ ? I don't know much about C++, and I'm still not able to find anything online that would give a reason blocking this. Does anyone know what terrible things would happen,…

Gábor Buella
- 1,840
- 14
- 22
25
votes
5 answers
Can C's restrict keyword be emulated using strict aliasing in C++?
The Problem
The restrict keyword in C is missing in C++, so out of interest I was looking for a way to emulate the same feature in C++.
Specifically, I would like the following to be equivalent:
// C
void func(S *restrict a, S *restrict b)
//…

PBS
- 1,389
- 11
- 20
17
votes
2 answers
Using restrict with arrays?
Is there a way to tell a C99 compiler that the only way I am going to access given array is by using myarray[index] ?
Say something like this:
int heavy_calcualtions(float* restrict range1, float* restrict range2)
{
float __I promise I won't…

Piotr Lopusiewicz
- 2,514
- 2
- 27
- 38
16
votes
3 answers
Is scanf("%d%d", &x, &x) well defined?
Is the following code well defined?
#include
int ScanFirstOrSecond(const char *s, int *dest) {
return sscanf(s, "%d%d", dest, dest);
}
int main(void) {
int x = 4;
ScanFirstOrSecond("5", &x);
printf("%d\n", x); // prints…

chux - Reinstate Monica
- 143,097
- 13
- 135
- 256
16
votes
3 answers
Parameters declared restrict and compiler warnings
Neither gcc 5 nor clang 3.6 give warnings where the constraints of the restrict qualifier are violated, even when called with -Wall. Consider the following code fragment:
extern void f(char *restrict p, char *restrict q);
void g(char *p)
{
…

jch
- 5,382
- 22
- 41
16
votes
2 answers
'restrict' keyword - Why is it allowed to assign from a outer restricted variable to an inner restricted variable?
First some references. The C99 Standard says this about restrict in section 6.7.3:
An object that is accessed through a restrict-qualified pointer has a
special association with that pointer. This association, defined in
6.7.3.1 below, requires…

Norswap
- 11,740
- 12
- 47
- 60
10
votes
2 answers
How to exclude a specific device brand/model when it is not shown in Google Play Console Device Catalog?
I'm trying to exclude the following device brand/model as this is not compatible with my app:
Brand: Trend
Model: TaintArt for x86
However, though this device appears continuously in my Crashlytics report, I cannot find it in the Device Catalog, so…

Pablo Alfonso
- 2,317
- 1
- 18
- 24
10
votes
2 answers
Why is the format in printf marked as restrict?
I just happened to look at the prototype of the printf (and other fprintf class of functions) -
int printf(const char * restrict format, ...);
The keyword restrict if I understand correctly disallows access to the same object through two pointers…

Ajay Brahmakshatriya
- 8,993
- 3
- 26
- 49
10
votes
1 answer
Why does clang ignore __restrict__?
I just tested a small example to check whether __restrict__ works in C++ on the latest compilers:
void foo(int x,int* __restrict__ ptr1, int& v2) {
for(int i=0;i

gexicide
- 38,535
- 21
- 92
- 152
10
votes
4 answers
Restrict file access -- only read through PHP
I am using a GoDaddy web hosting plan on a Windows platform. This was not my choice -- it has to do with a different part of the actual site using ASP.NET (also not my choice).
I have a SQL database with a bunch of entries with some non-sensitive…

altexpape
- 133
- 1
- 8
9
votes
2 answers
Is this behavior of clang standard compliant?
This is going to be a long, language lawyerish question, so I'd like to quickly state why I find it relevant. I am working on a project where strict standard compliance is crucial (writing a language that compiles to C). The example I am going to…

Kyle
- 878
- 6
- 14
8
votes
3 answers
Restrict input type="number" to its min or max if it is out of range
I have the below code
if a user enters a value in the textbox out of range then it should reset to its…

Joshi
- 573
- 3
- 11
- 24
7
votes
1 answer
restricting character set in a Textinput field
I have a TextInput field that should be restricted to either capital letters, lowercase letters, numbers and underscores. This is the code I'm trying to use to restrict characters:
restrict="\\A-Z\\a-z\\0-9\\ \\_\\-"
I'm using MXML for this…

StephenAdams
- 521
- 2
- 9
- 26
7
votes
3 answers
Opposite keyword of "restrict" in C?
Since strict aliasing may help compiler optimize better, C99 introduced the restrict keyword which can be used as a qualifier of a variable if programmers guarantee that it won't be accessed through a pointer to a different type. However,…

Kevin Dong
- 5,001
- 9
- 29
- 62
7
votes
0 answers
Avoiding loss of __restrict__ when using GSL spans
I (mostly) like the new C++ Core Guidelines initiative, and what the Guidelines Support Libary offers. Specifically, I want to use spans more. However, I'm coming up against the issue of __restrict__ not being part of C++ while I want to/need to…

einpoklum
- 118,144
- 57
- 340
- 684