Skip to content

Instantly share code, notes, and snippets.

@rrozestw
rrozestw / WhatIsStrictAliasingAndWhyDoWeCare.md
Created December 8, 2019 18:50 — forked from shafik/WhatIsStrictAliasingAndWhyDoWeCare.md
What is Strict Aliasing and Why do we Care?

What is the Strict Aliasing Rule and Why do we care?

(OR Type Punning, Undefined Behavior and Alignment, Oh My!)

What is strict aliasing? First we will describe what is aliasing and then we can learn what being strict about it means.

In C and C++ aliasing has to do with what expression types we are allowed to access stored values through. In both C and C++ the standard specifies which expression types are allowed to alias which types. The compiler and optimizer are allowed to assume we follow the aliasing rules strictly, hence the term strict aliasing rule. If we attempt to access a value using a type not allowed it is classified as undefined behavior(UB). Once we have undefined behavior all bets are off, the results of our program are no longer reliable.

Unfortunately with strict aliasing violations, we will often obtain the results we expect, leaving the possibility the a future version of a compiler with a new optimization will break code we th

@rrozestw
rrozestw / main.go
Created January 7, 2018 19:08 — forked from enricofoltran/main.go
A simple golang web server with basic logging, tracing, health check, graceful shutdown and zero dependencies
package main
import (
"context"
"flag"
"fmt"
"log"
"net/http"
"os"
"os/signal"
### Keybase proof
I hereby claim:
* I am rrozestw on github.
* I am rrozestwinski (https://keybase.io/rrozestwinski) on keybase.
* I have a public key whose fingerprint is DFCE 146E 17FE A6E2 0527 753D 9668 BCFC F9CA D34A
To claim this, I am signing this object:
#define USE_ROBIN_HOOD_HASH 1
#define USE_SEPARATE_HASH_ARRAY 1
template<class Key, class Value>
class hash_table
{
static const int INITIAL_SIZE = 256;
static const int LOAD_FACTOR_PERCENT = 90;
struct elem