156 questions
2
votes
2
answers
106
views
Is it undefined behaviour to free a `static restrict` array function parameter?
I'm asking this question from the perspective of a compiler developer – I want to know whether a particular potential optimisation is valid (because all programs that the optimisation would break have ...
Advice
0
votes
3
replies
97
views
Restrict keyword and pointers to pointers
I'm in C and I have an int ** (2 dimensional array, it's basically a matrix, it's actually set up a little bit complicated but there's no internal aliasing, so it's not relevant).
is this int** ...
2
votes
3
answers
194
views
What is the role of restrict here?
size_t hash(char const[restrict static 32]) [[reproducible]];
This is a function definition from Modern C by Jens Gustedt.
I understand that this is a more preferred alternate notation to a 32 char ...
0
votes
0
answers
91
views
Can a __restrict__ pointer be captured by a lambda?
I am aware that __restrict__ is not standard C++ and is instead an extension of C99 that GCC supports (previous question of mine: Uncertainty of GCC __restrict__ rules)
However, if we make some ...
3
votes
1
answer
146
views
How does the restrict keyword in C behave differently with pointers to structures compared to pointers to primitive types? [closed]
I’m trying to understand the nuances of the restrict keyword in C, particularly how its behavior might differ when applied to a pointer to a structure versus a pointer to a primitive type like int.
...
3
votes
3
answers
137
views
Is assigning to a restrict qualified pointer always undefined behavior?
My understanding of restrict qualified pointers in that no restrict qualified pointer may point to the same memory address as another pointer if both pointers are accessible within the same scope. (...
1
vote
2
answers
234
views
Include C99 code using the restrict keyword in C++ source
We use extern "C" { ... } to include C header files in C++. This does not seem to work if the C file uses C99 keywords such as restrict. For example:
test.h
#ifndef TEST_H
#define TEST_H
...
5
votes
1
answer
202
views
restrict Qualifier in C
Is the following valid usage of restrict qualifier in C or undefined behaviour?
#include <stdio.h>
int foo(float * restrict a) {
float a1 = *a;
float a2 = *(a+1);
float * restrict ...
4
votes
1
answer
124
views
Restricted access for allocated arrays belonging to separate object
I was thinking about the utility of non-standard __restrict keyword in C and C++ and how its effect can be emulated by carefully declare (disjoint) value objects .
Restrict is usually explained ...
1
vote
1
answer
122
views
Is it definitely not allowed to access the object pointed to by the pointer with the keyword 'restrict' using other pointers?
2011 6.7.3.1 says:
1 Let D be a declaration of an ordinary identifier that provides a means of designating an object P as a restrict-qualified pointer to type T.
2 If D appears inside a block and ...
0
votes
0
answers
74
views
Is this a good way of providing bounds checking while using __restrict__ keyword in C++
I am writing some C++ code and compiling with g++. I use the __restrict__ keyword on pointer arrays in some performance critical places to hopefully get better performance.
std::vector::operator[] has ...
6
votes
1
answer
96
views
Is the C restrict qualifier transitive through pointers?
Is the C restrict keyword/qualifier transitive through multiple levels of pointer indirection?
For instance, given the following snippet:
struct Bar {
int b;
};
struct Foo
{
struct Bar* bar;
}...
1
vote
1
answer
108
views
Why can a fpos_t * alias a FILE *?
In Modern C, Jens Gustedt states that:
With the exclusion of character types, only pointers of the same base type may alias.
But then I find this declaration of fgetpos() in Annex B of the C ...
3
votes
2
answers
252
views
Do C compilers follow the "formal definition of `restrict`"?
Consider this code:
extern int A[2];
/* Just returns `p` back. */
extern int *identity(int *p);
int f(int *restrict p)
{
int *q = identity(p); /* `q` becomes "based on" `p` */
int ...
1
vote
0
answers
66
views
When is `T *restrict`'s no-aliasing guarantee enforced?
If I have an aliasing T *restrict, but it is never used, is this considered undefined-behavior. Or is undefined behavior at the point of use.
For example
int *nothing = NULL;
int *restrict ...