Top "Strict-aliasing" questions

Strict aliasing is an assumption, made by the C or C++ compiler, that de-referencing pointers to objects of different types will never refer to the same memory location (i.e. they will not alias each other).

What is the strict aliasing rule?

When asking about common undefined behavior in C, people sometimes refer to the strict aliasing rule. What are they talking …

c undefined-behavior strict-aliasing type-punning
Dereferencing type-punned pointer will break strict-aliasing rules

I used the following piece of code to read data from files as part of a larger program. double data_…

c optimization gcc pointers strict-aliasing
Fix for dereferencing type-punned pointer will break strict-aliasing

I'm trying to fix two warnings when compiling a specific program using GCC. The warnings are: warning: dereferencing type-punned pointer …

c strict-aliasing type-punning
"dereferencing type-punned pointer will break strict-aliasing rules" warning

I use a code where I cast an enum* to int*. Something like this: enum foo { ... } ... foo foobar; int *pi = …

c++ warnings strict-aliasing
gcc, strict-aliasing, and horror stories

In gcc-strict-aliasing-and-casting-through-a-union I asked whether anyone had encountered problems with union punning through pointers. So far, the answer seems to …

c gcc strict-aliasing
gcc, strict-aliasing, and casting through a union

Do you have any horror stories to tell? The GCC Manual recently added a warning regarding -fstrict-aliasing and casting a …

c gcc type-conversion unions strict-aliasing
How to cast sockaddr_storage and avoid breaking strict-aliasing rules

I'm using Beej's Guide to Networking and came across an aliasing issue. He proposes a function to return either the …

c sockets aliasing strict-aliasing
reinterpret_cast between char* and std::uint8_t* - safe?

Now we all sometimes have to work with binary data. In C++ we work with sequences of bytes, and since …

c++ c++11 language-lawyer strict-aliasing uint8t
Correct, portable way to interpret buffer as a struct

The context of my problem is in network programming. Say I want to send messages over the network between two …

c networking portability strict-aliasing
What's a proper way of type-punning a float to an int and vice-versa?

The code below performs a fast inverse square root operation by some bit hacks. The algorithm was probably developed by …

c++ undefined-behavior gcc-warning strict-aliasing type-punning