2 ms·
quux_t *foo(int i) { /* Trick to prevent compiler from inlining */ if(i == 0) { quux_t *bar = (quux_t *) malloc(sizeof(quux_t));
by jedbrown 16y ago
quux_t *foo(int i) {
/* Trick to prevent compiler from inlining */
if(i == 0) {
quux_t *bar = (quux_t *) malloc(sizeof(quux_t));
return bar;
} else {
return foo(0);
}
}
Seriously? GCC removes this obfuscation at -O2, Clang does it at -O1. Check the disassembly before making stupid claims like this.
- liuliu 16y agoHe can use __attribute__ to enforce noinline: http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html Though these flags are gcc specific (works in clang as well). I found it to be tremendously useful in some cases.