70 questions
-2
votes
2
answers
148
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
251
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 ...
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 ...
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
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 ...
4
votes
3
answers
183
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
0
answers
59
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
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()...
4
votes
0
answers
262
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');
...
8
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 ...
0
votes
2
answers
234
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 &&...
3
votes
2
answers
396
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 ...
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....
-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 ...
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
105
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] ...
-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 ...
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
[...
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
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 ...
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
1
answer
162
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 ...
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 ...
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 ...
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 ...