4 ms·
This is an extremely useful trick for foiling the optimizer. To make it explicit, it goes like this: asm volatile("" : "+r"(my_val) ::); This means "an em
by thrtythreeforty 3y ago
This is an extremely useful trick for foiling the optimizer. To make it explicit, it goes like this:
asm volatile("" : "+r"(my_val) ::);
This means "an empty assembly statement that you must assume contains side effects, and takes my_val as an input register and modifies it somehow." Note that because there is no assembly, this is perfectly portable (across architectures, maybe not across compilers, since only GCC and Clang know this syntax).
I've used it to get the compiler to forget that function pointers cannot be null, for example.
Of course you are still in "implementation defined behavior" land re: the standard. But it's often pretty easy to reason like the compiler does once you know your target architecture, and once your values are all unconstrained integers.