3 ms·
I was once told that optimizations in the sense of dead code elimination the way clang does it could be bypassed by making a variable volatile... Wouldn't that
by mar77i 8y ago
I was once told that optimizations in the sense of dead code elimination the way clang does it could be bypassed by making a variable volatile... Wouldn't that help here as well?
volatile unsigned char *p = malloc(w * h);
...
- pubby 8y agoI tested it. It doesn't help on Clang.
- Ded7xSEoPKYNsDd 8y agoThe volatile modified on a pointer tells the compiler that reads and writes to it can have side-effects -- it is meant for memory-mapped hardware registers. Because of those (presumed) side-effects, reads and writes to that volatile pointer cannot be optimized away by dead code elimination. Changing the address where such a variable points to, will still be optimized away when it isn't used later on.
- dooglius 8y agoNot quite, what you want is unsigned char * volatile p = malloc(w * h); This indicates that p itself is a volatile variable, rather than a pointer to memory that is volatile.
- mar77i 8y agoAh, that was the thing I was after. Thanks.