Questions tagged [pointer-aliasing]

59 questions
5
votes
2 answers

Exception to strict aliasing rule in C from 6.5.2.3 Structure and union members

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), and if the union object currently contains one of…
user1143634
4
votes
1 answer

Where can I find what std::launder really does?

I am trying to understand what std::launder does, and I hoped that by looking up an example implementation it would be clear. Where can I find an example implementation of std::launder? When I looked in lbic++ I see a code like template
alfC
  • 14,261
  • 4
  • 67
  • 118
4
votes
3 answers

Create alias of part of a list in python

Is there a way to get an alias for a part of a list in python? Specifically, I want the equivalent of this to happen: >>> l=[1,2,3,4,5] >>> a=l >>> l[0]=10 >>> a [10, 2, 3, 4, 5] But what I get is this: >>> l=[1,2,3,4,5] >>> a=l[0:2] >>>…
db_
  • 103
  • 1
  • 2
  • 7
4
votes
1 answer

pointer aliasing

what is the difference between "Strict", "Typed", "Restricted" and "Disjointed" aliasing?
salman
  • 1,966
  • 3
  • 15
  • 18
3
votes
0 answers

Mutable reference and pointer aliasing

Consider the following code: unsafe { let mut s = "".to_string(); let r = &mut s; let ptr = r as *mut String; r.push('a'); (*ptr).push('b'); r.push('c'); (*ptr).push('d'); println!("{}",…
rubo
  • 377
  • 1
  • 8
3
votes
2 answers

Python aliasing

I understand that given this code a = [1,2,3] b = [4,5,6] c = a and then by doing this a[0] = 0 I wil change first positions of both a and c. Could somebody explain why this doesn't apply when I do this: a = b ie. why c doesn't become equal to b?
kubajed
  • 31
  • 1
2
votes
3 answers

restrict-edness with pre-c99

Considering this code, VC9 doesn't detect aliasing : typedef struct { int x, y; } vec_t; void rotate_cw(vec_t const *from, vec_t *to) { /* Notice x depends on y and vice versa */ to->x = from->y; to->y =…
diapir
  • 2,872
  • 1
  • 19
  • 26
2
votes
2 answers

What's the duration of "pointer not aliased by any other pointer" implication?

Currently Visual C++ is shipped with runtime where malloc() is decorated with __declspec( restrict ). MSDN says this decoration states to the compiler that a pointer returned by malloc() cannot be aliased by any other pointer. Okay, two subsequent…
sharptooth
  • 167,383
  • 100
  • 513
  • 979
2
votes
2 answers

What is the register cache and what does it have to do with const variables?

From http://www.parashift.com/c++-faq-lite/const-correctness.html#faq-18.14: Even if the language outlawed const_cast, the only way to avoid flushing the register cache across a const member function call would be to solve the aliasing problem…
2
votes
2 answers

Aliasing and pointer-interconvertability

Given the following code: struct Tag {}; struct X { // Tag t; // if not commented it shouldn't be pointer-interconvertible int k; }; int fn(const X& x, int& p) { int i = x.k; p = 2; return i + x.k; } The generated code is: fn(X…
wimalopaan
  • 4,838
  • 1
  • 21
  • 39
2
votes
2 answers

How to manage shared_ptr that points to internal data of already referenced object?

Suppose I have these classes: struct Engine { int engine_data; }; struct Car { shared_ptr engine; int car_data; }; For performance reasons, I want to make them tightly packed in memory (but I don't want to lose the flexibility of the…
e.tadeu
  • 5,024
  • 2
  • 20
  • 21
2
votes
1 answer

Different behaviour of a nested query on 2 different SQL Server 2008 R2

The following query returns two different results on two instances of SQL Server 2008 R2: create table a(id int) insert into a(id) values(1) insert into a(id) values(2) select id, (select count(dbo.a.id) from dbo.a where dbo.a.id =…
2
votes
2 answers

Strange performance problem

I have a container similar to this one. template class NatMap { public: Elt& operator[] (Nat nat) { return tab [nat.GetRaw()]; } private: Elt tab [Nat::kBound]; }; I wanted to drop the requirement for Elt…
Łukasz Lew
  • 48,526
  • 41
  • 139
  • 208
2
votes
1 answer

Examples of strict aliasing of pointers in GCC C99, no performance differences

I'm trying to understand the impact of strict aliasing on performance in C99. My goal is to optimize a vector dot product, which takes up a large amount of time in my program (profiled it!). I thought that aliasing could be the problem, but the…
purple51
  • 319
  • 1
  • 8
1
vote
1 answer

Why does black-on-white text render to a non-grayscale RGB image?

Zooming in at any screenshot of black text on white background reveals a colorful image with bluish right fringes and reddish left fringes: While I didn't expect the image to be binary black and white because of aliasing, I expected it to be…
MrX
  • 141
  • 2
  • 6