I am working on implementing a std::function myself. To do small object optimization I need to implement a storage which maybe store the object locall ...
I am working on implementing a std::function myself. To do small object optimization I need to implement a storage which maybe store the object locall ...
The code included below is a stripped-down implementation of a function that generates a UDP packet for a given fixed-size payload and sends it. Afte ...
I'm interested in the technique used by Sean Barrett to make a dynamic array in C for any type. Comments in the current version claims the code is saf ...
I have a (char*) buffer. Am I allowed to do as follows: int8_t i8 = *(int8_t*)buffer; int16_t i16 = *(int16_t*)buffer; float f = *(float*)bu ...
I'm currently working on a project where I often have to build linked lists of various C structs. Since I don't want to keep repeating myself setting ...
Can I use a std::array<int, N> to alias parts of a int[] without invoking UB? https://en.cppreference.com/w/cpp/container/array "This container ...
An external API expects a pointer to an array of values (int as simple example here) plus a size. It is logically clearer to deal with the elements i ...
This example is copied from cppreference. struct Y { int z; }; alignas(Y) std::byte s[sizeof(Y)]; Y* q = new(&s) Y{2}; const int f = reinterpret_ ...
Given type definitions and a function taking struct a* a and struct b* b, the type information expresses possible overlap between a->a and b-> ...
In C (let's say C11 if we need to specific), is the following program well-defined? Will it always print a=3 b=4 or could compiler optimizations affec ...
Reading https://en.cppreference.com/w/cpp/language/reinterpret_cast I wonder what are use-cases of reinterpret_cast that are not UB and are used in pr ...
. This question is not currently accepting new answers or interactions. Learn ...
I have the following sample code: Under x86-64 clang 13.0.1, the code compiles as expected. Under x86-64 clang 14.0.0 or 15, the output is merely ...
According to this answer the following code invokes undefined behavior: We may write any type to malloc() memory but we may not read a previously w ...
I recently discovered strict aliasing rule in C/C++ and now I am try to remedy at some part of my code where it was present. I am given a buffer of u ...
I learned unfortunately too late about strict-aliasing rule and C/C++ legit dereference after cast. As far as I understand the following code does bre ...
I'm trying to implement a polymorphic data structure e.g. an intrusive linked list (I already know the kernel has one - this is more of learning exper ...
I was scrolling through some posts and I read about something called the strict aliasing rule. It looked awfully close to some code I've seen in a clu ...
Consider the following MRE: #include <arm_neon.h> void test(int64_t *r) { int32x4x2_t vr; // Do something actually interesting here inste ...
I believe 6.5p7 in the C standard defines the so-called strict aliasing rule as follows. An object shall have its stored value accessed only by an ...