Skip to content

Instantly share code, notes, and snippets.

@thecppzoo
thecppzoo / IntegerOverflowUndefinedBehavior.md
Last active September 5, 2017 01:26
Undefined behavior about integer overflow

Overflowing an integer is undefined behavior. Then the compiler is allowed to assume you are not going to overflow integers and optimize accordingly.

I was doing some delicate bit-fiddling code and got a surprise, that if you put in a file this

#include <stdint.h>

void consume(bool);

extern long maxInt;