pointer-aliasing Questions
2
This is a follow up to this question, Restricted access for allocated arrays belonging to separate object, after discovering that returning by value across compilation units doesn't help to hint th...
Fauch asked 21/10 at 18:23
3
Solved
Suppose I have a function which takes some pointer parameters - some non-const, through which it may write, and some const through which it only reads. Example:
void f(int * a, int const *b);
Supp...
Quan asked 5/9 at 9:27
4
Solved
I have function that receives an array of pointers like so:
void foo(int *ptrs[], int num, int size)
{
/* The body is an example only */
for (int i = 0; i < size; ++i) {
for (int j = 0; j ...
Frigorific asked 7/9, 2011 at 3:8
2
Solved
g++ does implement __restrict__ for pointers, but I could not find anything about iterators. My overall intent is to encourage the compiler to vectorize stl loops.
Edit:
Even if the compiler is una...
Honeysuckle asked 13/2, 2011 at 10:52
1
I was working on highly "vectorizable" code and noted that regarding the C++ __restrict keyword/extension ~, Clang's behavior is different and impractical compared to GCC even in a simple...
Broadspectrum asked 13/12, 2021 at 18:29
2
Solved
In unsafe code, is it correct to have several mutable references (not pointers) to the same array, as long as they are not used to write to the same indices?
Context
I would like to yield several...
Pockmark asked 11/2, 2019 at 15:7
2
Solved
Quote from C99 standard:
6.5.2.3
5 One special guarantee is made in order to simplify the use of unions: if a union contains several structures that share a common initial sequence (see below), an...
Bultman asked 17/1, 2014 at 0:44
4
Solved
I'm using Beej's Guide to Networking and came across an aliasing issue. He proposes a function to return either the IPv4 or IPv6 address of a particular struct:
1 void *get_in_addr( struct sockadd...
Baggett asked 15/9, 2009 at 21:10
3
Solved
I have gone through some queries on the similar topic and some material related to it.
But my query is mainly to understand the warning for the below code. I do not want a fix !!
I understand there...
Contravene asked 23/5, 2014 at 5:0
3
Solved
If dot_product is declared as
float dot_product(const float* restrict a, const float* restrict b, unsigned n);
would calling it with
dot_product(x, x, x_len)
be "undefined", according to the...
Kropp asked 18/12, 2013 at 9:16
3
Solved
Consider this hypothetical implementation of vector:
template<class T> // ignore the allocator
struct vector
{
typedef T* iterator;
typedef const T* const_iterator;
template<class It&...
Dip asked 20/8, 2012 at 2:52
5
I understand that having a const method in C++ means that an object is read-only through that method, but that it may still change otherwise.
However, this code apparently changes an object throug...
Firn asked 18/6, 2012 at 5:57
4
Solved
Please consider the following code:
typedef struct {
int type;
} object_t;
typedef struct {
object_t object;
int age;
} person_t;
int age(object_t *object) {
if (object->type == PERSON) {...
Uninterested asked 7/12, 2011 at 13:54
1
Solved
Having recently read that the main reason why fortran is faster than c/c++ in numerical computations is because there is no pointer aliasing.
Apparently, using restrict or __restrict__ keywords al...
Incrassate asked 4/9, 2011 at 10:21
1
Does the following code invoke undefined behavior (due to aliasing violation or otherwise)?
int foo(int (*a)[10], int (*b)[5])
{
(*a)[5]++;
return (*b)[0];
}
int x[10];
foo(&x, (int (*)[5])...
Lab asked 15/8, 2011 at 4:39
5
std::vector<int> a;
a.push_back(1);
a.push_back(a[0]);
I just learned that the code above can be very dangerous.
(If it's not obvious why, you're not alone... it wasn't obvious to me either....
Haileyhailfellowwellmet asked 2/6, 2011 at 5:13
4
Solved
I've got some code that I've been using successfully for some years to implement a "variant-type object"; that is, a C++ object that can hold a values of various types, but only uses (approximately...
Linkwork asked 23/11, 2010 at 23:2
1
© 2022 - 2024 — McMap. All rights reserved.