Skip to content

Instantly share code, notes, and snippets.

@rygorous
rygorous / gist:e0f055bfb74e3d5f0af20690759de5a7
Created May 8, 2016 06:54
A bit of background on compilers exploiting signed overflow
Why do compilers even bother with exploiting undefinedness signed overflow? And what are those
mysterious cases where it helps?
A lot of people (myself included) are against transforms that aggressively exploit undefined behavior, but
I think it's useful to know what compiler writers are accomplishing by this.
TL;DR: C doesn't work very well if int!=register width, but (for backwards compat) int is 32-bit on all
major 64-bit targets, and this causes quite hairy problems for code generation and optimization in some
fairly common cases. The signed overflow UB exploitation is an attempt to work around this.
@kylelemons
kylelemons / valsort.go
Created September 22, 2011 21:36
Sort a map by its values
package main
import "fmt"
import "sort"
func main() {
m := map[string]int{
"One": 1,
"Two": 2,
"Three": 3,