Skip to main content
Filter by
Sorted by
Tagged with
-2 votes
2 answers
151 views

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 ...
fghoussen's user avatar
  • 599
5 votes
2 answers
265 views

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 ...
alfC's user avatar
  • 16.8k
4 votes
1 answer
196 views

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 ...
drex's user avatar
  • 71
0 votes
1 answer
146 views

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 ...
akyoshid's user avatar
8 votes
3 answers
229 views

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 ...
einpoklum's user avatar
  • 138k
1 vote
0 answers
25 views

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 ...
Angela's user avatar
  • 11
1 vote
1 answer
109 views

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 ...
Madagascar's user avatar
  • 7,470
1 vote
1 answer
117 views

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 ...
einpoklum's user avatar
  • 138k
2 votes
2 answers
202 views

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 ...
Samuel's user avatar
  • 31
4 votes
3 answers
193 views

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; ...
Hren Sgory's user avatar
0 votes
1 answer
216 views

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, ...
ricardo's user avatar
0 votes
0 answers
60 views

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,...
Pacifico's user avatar
0 votes
1 answer
159 views

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:...
user35939's user avatar
0 votes
0 answers
40 views

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()...
NiceGuy's user avatar
  • 11
0 votes
1 answer
476 views

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 ...
Catchi's user avatar
  • 21
4 votes
0 answers
263 views

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'); ...
rubo's user avatar
  • 437
1 vote
1 answer
509 views

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 ...
Doron Shafrir's user avatar
9 votes
1 answer
2k views

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 ...
Etienne M's user avatar
  • 733
1 vote
1 answer
132 views

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 ...
Jarvis__-_-__'s user avatar
0 votes
2 answers
238 views

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 &&...
Harry K.'s user avatar
  • 650
0 votes
2 answers
2k views

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 { ...
Jarom Allen's user avatar
3 votes
2 answers
397 views

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 ...
kubajed's user avatar
  • 31
2 votes
2 answers
319 views

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; ...
wimalopaan's user avatar
  • 5,572
0 votes
1 answer
52 views

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....
Turboninja99's user avatar
7 votes
2 answers
1k views

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 (...
rom1v's user avatar
  • 3,049
-2 votes
1 answer
84 views

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 ...
Clifford's user avatar
0 votes
2 answers
145 views

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; ...
Filipp's user avatar
  • 2,092
4 votes
1 answer
3k views

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 ...
alfC's user avatar
  • 16.8k
0 votes
1 answer
53 views

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 ...
JTinHearth's user avatar
0 votes
1 answer
108 views

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] ...
user1519226's user avatar
0 votes
1 answer
122 views

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 ...
user541686's user avatar
  • 213k
-3 votes
1 answer
76 views

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 ...
Arik Shalito's user avatar
0 votes
2 answers
700 views

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 ...
Morty's user avatar
  • 1,766
4 votes
3 answers
5k views

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 [...
db_'s user avatar
  • 653
0 votes
2 answers
55 views

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;...
Hovestar's user avatar
  • 1,627
1 vote
1 answer
317 views

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 ...
user3673010's user avatar
1 vote
3 answers
1k views

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 ...
Andrea Biagioni's user avatar
1 vote
4 answers
2k views

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 ...
makansij's user avatar
  • 9,995
6 votes
3 answers
944 views

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 ...
DarkKnight's user avatar
0 votes
4 answers
4k views

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 ...
carles's user avatar
  • 360
0 votes
0 answers
111 views

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 ...
user3332240's user avatar
0 votes
1 answer
163 views

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 ...
user3313599's user avatar
5 votes
2 answers
2k views

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 ...
user avatar
6 votes
3 answers
1k views

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 ...
MWB's user avatar
  • 12.7k
0 votes
1 answer
240 views

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; } ...
user979033's user avatar
  • 6,752
2 votes
1 answer
323 views

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 ...
user2598804's user avatar
1 vote
2 answers
572 views

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....
user0002128's user avatar
  • 2,961
0 votes
1 answer
50 views

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 ...
Assaf's user avatar
  • 1,124
2 votes
1 answer
394 views

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 ...
purple51's user avatar
  • 319
6 votes
3 answers
189 views

Consider this hypothetical implementation of vector: template<class T> // ignore the allocator struct vector { typedef T* iterator; typedef const T* const_iterator; template<...
user541686's user avatar
  • 213k