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]
342 questions
33
votes
2 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,…
![](../../users/profiles/875023.webp)
Gábor Buella
- 1,632
- 13
- 19
23
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)
//…
![](../../users/profiles/5075760.webp)
PBS
- 1,324
- 8
- 19
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…
![](../../users/profiles/2410359.webp)
chux - Reinstate Monica
- 113,725
- 11
- 107
- 213
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…
![](../../users/profiles/298664.webp)
Norswap
- 10,130
- 10
- 42
- 57
15
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)
{
…
![](../../users/profiles/4127569.webp)
jch
- 4,491
- 16
- 36
12
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…
![](../../users/profiles/498981.webp)
Piotr Lopusiewicz
- 2,274
- 2
- 24
- 33
10
votes
1 answer
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…
![](../../users/profiles/5394986.webp)
Pablo Alfonso
- 1,792
- 1
- 11
- 20
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…
![](../../users/profiles/419012.webp)
altexpape
- 133
- 1
- 8
9
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
![](../../users/profiles/1408611.webp)
gexicide
- 35,369
- 19
- 80
- 136
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…
![](../../users/profiles/5402249.webp)
Kyle
- 806
- 4
- 12
8
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…
![](../../users/profiles/2858773.webp)
Ajay Brahmakshatriya
- 8,213
- 3
- 19
- 41
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…
![](../../users/profiles/207721.webp)
StephenAdams
- 521
- 2
- 8
- 26
7
votes
1 answer
how do i restrict ip block -range- using htaccess?
This is the IP range I wish to block 61.19.0.0 - 61.19.255.255
I've google it and found a few information's, but how do you continue the restriction list?
First block /18 starting at 0: 0-63 (64 class C addresses)
then block /20 starting…
![](../../users/profiles/2226078.webp)
john
- 123
- 1
- 2
- 8
7
votes
1 answer
What is the purpose of restrict in tmpfile_s?
From C11 draft:
C11 (n1570), § K.3.5.1.1 The tmpfile_s function
errno_t tmpfile_s(FILE * restrict * restrict streamptr);
What is the purpose of the restrict qualifier here?
Because there is no other parameters, the compiler is able to know that…
![](../../users/profiles/1126268.webp)
md5
- 22,211
- 2
- 40
- 91
6
votes
1 answer
Is there a way to tell the C compiler that a pointer has no aliasing stores?
If the C compiler knows that a pointer is not aliased, it can perform many optimizations. For example, if I compile the following function with gcc -O2:
int f_noalias(int *arr, int x)
{
int res = 0;
int *p = &arr[17];
*p = x;
res +=…
![](../../users/profiles/90511.webp)
hugomg
- 63,082
- 19
- 144
- 230