Skip to content

Instantly share code, notes, and snippets.

@amin-jabri
amin-jabri / WhatIsStrictAliasingAndWhyDoWeCare.md
Created December 26, 2020 01:38 — 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

Keybase proof

I hereby claim:

  • I am amin-jabri on github.
  • I am jabri (https://keybase.io/jabri) on keybase.
  • I have a public key whose fingerprint is E2C7 02A0 8BE6 FF34 F1FB 52B8 C521 5748 AE1E 3925

To claim this, I am signing this object:

@amin-jabri
amin-jabri / gist:7391afef239feb37259522aade4df4fa
Created April 28, 2016 07:19 — forked from dedy-purwanto/gist:11312110
Bulk remove iTerm2 color schemes.
# There was a day where I have too many color schemes in iTerm2 and I want to remove them all.
# iTerm2 doesn't have "bulk remove" and it was literally painful to delete them one-by-one.
# iTerm2 save it's preference in ~/Library/Preferences/com.googlecode.iterm2.plist in a binary format
# What you need to do is basically copy that somewhere, convert to xml and remove color schemes in the xml files.
$ cd /tmp/
$ cp ~/Library/Preferences/com.googlecode.iterm2.plist .
$ plutil -convert xml1 com.googlecode.iterm2.plist
$ vi com.googlecode.iterm2.plist
@amin-jabri
amin-jabri / main.cpp
Created October 19, 2015 10:20 — forked from splinterofchaos/main.cpp
clang 3.4 tests
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <string>
#include <cmath>
#include <future>