69 questions
-2
votes
2
answers
151
views
Equivalence between std::vector<std::array<double>> and std::vector<double>
Can I use the pointer returned by std::vector<std::array<double>>::data()::data() as a pointer returned by an equivalent std::vector<double>::data()?
Do I expose myself to potential ...
5
votes
2
answers
265
views
Tricks to avoid pointer aliasing in generic code
This is a follow up to Restricted access for allocated arrays belonging to separate object after discovering that returning by value across compilation units doesn't help to hint the compiler about ...
4
votes
1
answer
196
views
Incrementing pointers in bytes for indexing strided array
I wrote a library whose interface references coordinate data from client side. Clients are expected to provide an array of points that each contains 3 contiguous floats. I have decided to use a ...
0
votes
1
answer
146
views
Are there any strict aliasing rule violations that are not detected by -Wstrict-aliasing?
I created a function that copies strings quickly by copying 8 bytes at a time, similar to the built-in memcpy. In the following function, the char pointer type is cast to an unsigned long long pointer ...
8
votes
3
answers
229
views
Is it enough to only restrict the "out"-(pointer-)parameters of a function?
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);
Suppose ...
1
vote
0
answers
25
views
aliasing String arguments and parameters for methods in Java [duplicate]
I know that when you pass an object in as an argument to a method, the formal parameter object in that method becomes an alias of the argument/actual parameter. Unless that's actaully wrong, I don't ...
1
vote
1
answer
109
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 ...
1
vote
1
answer
117
views
Wrap a function without changing the call sites?
Suppose a function int foo(int x) is made available in library libfoo, which I don't control. I do control a codebase which calls foo() many times, in many files.
Now, I would like to insert some ...
2
votes
2
answers
202
views
Correctly reinterpreting array of struct of int as array of int
I have a std::vector of a custom struct which contains two integers (and only two integers):
struct S {
int p0;
int p1;
};
std::vector<S> v(dimension);
I want a pointer to this array ...
4
votes
3
answers
193
views
Is it safe to change data via a pointer when another pointer-to-const observes it?
Is it a safe code, or can the compiler optimize access through p, such that *p will result in 42?
#include <stdio.h>
int i = 42;
int *d = &i;
void test(int const *p)
{
*d = 43;
...
0
votes
1
answer
216
views
My pixijs app 'destroy' pixel when I downsize a big jpeg
I use Pixi.js and I want to down-size a big JPEG but the quality of the picture is affected.
I load the picture like this:
this.App = new PIXI.Application({ background: 'black', resizeTo: window, ...
0
votes
0
answers
60
views
Managing inventory with multiple SKUs and shared quantities in MySQL Database using Navicat
I have a database where the columns in one of the tables are:
UPC, SKU, AliasOf, Quantity
123456789123, 123456789123a, null, 6
123456789123, 123456789123b, 123456789123a, 0
123456789123, 123456789123c,...
0
votes
1
answer
159
views
reuse variable inside yaml for use in c++
I am trying to reuse a variable inside a yaml file which is then going to be read inside a c++ (visual studio). My attempt is not working at the moment. Here is my approach:
Inside yaml file:
testName:...
0
votes
0
answers
40
views
Calculating a summary of tuples' length not including aliasing in python
Given the following code, I've been asked to calculate how many different tuples (aliasing tuples are to be excluded) are in the returned tuple of the function:
def tuple_maker(k):
result = tuple()...
0
votes
1
answer
476
views
why customtkinter elements have a strange shape
I'm trying to use customtkinter. i downloaded the examples and when i try theme, all the elements have a strange shape enter image description here which don't look like the screens of the examples on ...
4
votes
0
answers
263
views
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');
...
1
vote
1
answer
509
views
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 ...
9
votes
1
answer
2k
views
Clang's __restrict is inconsistent?
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 ...
1
vote
1
answer
132
views
How to do aliasing with union or possible with enum?
I have gone through this very good article
https://stackoverflow.com/questions/98650/what-is-the-strict-aliasing-rule
but I didn't understood of aliasing with union, what I know about aliasing is ...
0
votes
2
answers
238
views
Preventing memory aliasing when copying mem blocks in C
I think I'm getting rusty, so please bare with me. I'll try to be brief.
Q1. When trying to copy buffers, say buf2 to buf1, does the following check suffice against aliasing?
if (buf2 >= buf1 &&...
0
votes
2
answers
2k
views
C++ template/aliasing - Type/value mismatch at argument 1 in template parameter list
I'm getting my feet wet with aliasing in templated classes, and haven't been able to compile the following code:
template <class T> using item_ptr = std::shared_ptr<T>;
class Container
{
...
3
votes
2
answers
397
views
Python aliasing [duplicate]
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 ...
2
votes
2
answers
319
views
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;
...
0
votes
1
answer
52
views
Why is my base case being (erroneously) triggered immediately?
I am trying to implement a merge sort algorithm in C. In the recursive array split function, my base case is occurring infinitely, despite the return statement, and the merge function is never called....
7
votes
2
answers
1k
views
Is aliasing of mutable references correct in unsafe code?
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 (...
-2
votes
1
answer
84
views
Algorithms, 4th Edition: do not understand an example about aliasing/reference
Counter c1 = new Counter("ones");
c1.increment();
Counter c2 = c1;
c2.increment();
StdOut.println(c1);
class code link: https://introcs.cs.princeton.edu/java/33design/Counter.java
public class ...
0
votes
2
answers
145
views
Using negative array index to access preceeding member
I'd like to use a negative array index to access the same-type member that immediately precedes that array in a struct.
Consider this type of code:
union hello {
int a[2];
struct { int b0; ...
4
votes
1
answer
3k
views
Where can I find what std::launder really does? [duplicate]
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 ...
0
votes
1
answer
53
views
Attempting to alter a copy but instead altering the original :(
I'm trying to make a 'smart' opponent in my Tic Tac Toe program. To do this I've created a 'possible win' function which will decide if there is a possible win in the next turn. My problem when ...
0
votes
1
answer
108
views
using aliasing to iterate through list once (python)
Say I have a list called list, which is comprised of boolean values. Also say that I have some (valid) index i which is the index of list where I want to switch the value.
Currently, I have: list[i] ...
0
votes
1
answer
122
views
Does NumPy handle 1:1 aliasing of complex-number operations correctly?
Say a and b are disjoint 1D complex NumPy arrays, and I do numpy.multiply(a, b, b).
Is b guaranteed to contain the same values as I would get via b[:] = numpy.multiply(a, b)?
I haven't actually been ...
-3
votes
1
answer
76
views
What happens behind the scenes(heap,stack,etc..) when adding a Node to the a LinkedList?
public void addToHead(IntNode node) {
IntNode temp = _head;
_head = node;
node.setNext(temp);
}
edit:I searched youtube, Nothig there about linkedlist and the heap
When does the garbage ...
0
votes
2
answers
700
views
Strict aliasing and writing int via char*
In an old program I serialized a data structure to bytes, by allocating an array of unsigned char, and then converted ints by:
*((*int)p) = value;
(where p is the unsigned char*, and value is the ...
4
votes
3
answers
5k
views
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
[...
0
votes
2
answers
55
views
Deallocating item in array
It if have an object, lets call it o, and two arrays typeo *a,*b; if I assign o to both array a and array b then delete[] b what happens if I try to access o or o in a? For example:
struct name{int a;...
1
vote
1
answer
317
views
Array Changes Not Showing Up in Main Method
This code is supposed to perform a "perfect shuffle" on a deck of cards. It represents the division of a deck into two decks and then the subsequent interleaving of them. When I pass in an array and ...
1
vote
3
answers
1k
views
What happen to stack when i declare a reference variable? C++
When i declare a variable, it will be allocated in stack at a certain index of memory right?
But when i declare a reference variable it will point to the same index of the other one, so no new ...
1
vote
4
answers
2k
views
Is there aliasing in a 2-D array in Python?
I know that list aliasing is an issue in Python, but I can't figure out a way around it.
def zeros(A):
new_mat = A
for i in range(len(A)):
for j in range(len(A[i])):
if ...
6
votes
3
answers
944
views
Consequenes of warning “dereferencing type-punned pointer will break strict-aliasing rules”
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 ...
0
votes
4
answers
4k
views
Unable to overwrite pathInfo in a Symfony 2 Request
I'm trying to deal with aliases (friendly-urls) and probably I'm not doing it right. What I want to do is to transform urls like '/blog/my-post-about-something' into '/posts/23'.
I have written a ...
0
votes
0
answers
111
views
Pointer aliasing and Performance improvement
Quick question (hopefully it is clear).
I was told that performance when considering speed can be drastically improved if you handle the problem of pointer aliasing (always reloading values from ...
0
votes
1
answer
163
views
Aliasing in objects
When running the function foo1, why does the output for this code will be: 15 30 5
and not 15 15 5 ?
I underdtand that the pointer of the object v is now points to the object va1, so the output for ...
5
votes
2
answers
2k
views
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 ...
6
votes
3
answers
1k
views
Is it legal to alias "const restrict" pointer arguments?
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 C99 ...
0
votes
1
answer
240
views
Aliasing example, try to understand this issue
I try to learn about Aliasing and encounter this example:
public class A
{
// Instance variable
private double _x;
// 3 constructors
public A(double x)
{
_x = x;
}
...
2
votes
1
answer
323
views
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 ...
1
vote
2
answers
572
views
Does CUDA support pointer-aliasing?
The reason why I ask this is because there is some strange bug in my code and I suspect it could be some aliasing problem:
__shared__ float x[32];
__shared__ unsigned int xsum[32];
int idx=threadIdx....
0
votes
1
answer
50
views
setObject() Method and aliasing
I have a LINE class that has two attributes of type POINT (which is an object).
public class LINE {
private Point p1,p2;
}
If I make this statement, will it cause aliasing?
public void setP1(Point ...
2
votes
1
answer
394
views
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 ...
6
votes
3
answers
189
views
How to correctly (yet efficiently) implement something like "vector::insert"? (Pointer aliasing)
Consider this hypothetical implementation of vector:
template<class T> // ignore the allocator
struct vector
{
typedef T* iterator;
typedef const T* const_iterator;
template<...