Integer overflow in C: standards and compilers

Take a look at -ftrapv and -fwrapv: -ftrapv This option generates traps for signed overflow on addition, subtraction, multiplication operations. -fwrapv This option instructs the compiler to assume that signed arithmetic overflow of addition, subtraction and multiplication wraps around using twos-complement representation. This flag enables some optimizations and disables other. This option is enabled by … Read more

Golang: How to cross compile on Linux for Windows

To build from Linux to Windows, you need to set the environment variables GOOS to Windows and GOARCH to amd64. On Bash or ZSH: % GOOS=windows GOARCH=amd64 go build For more details see: https://dave.cheney.net/2015/08/22/cross-compilation-with-go-1-5 A description of possible values for GOOS and GOARCH is available here: https://golang.org/doc/install/source#environment If your package requires CGO then you need … Read more

gcc -O0 still optimizes out “unused” code that should raise an FP exception. Is there a compile flag to change that?

Why does gcc not emit the specified instruction? A compiler produces code that must have the observable behavior specified by the Standard. Anything that is not observable can be changed (and optimized) at will, as it does not change the behavior of the program (as specified). How can you beat it into submission? The trick … Read more

tech