The difference between asm, asm volatile and clobbering memory
When implementing lock-free data structures and timing code it's often necessary to suppress the compiler's optimisations. Normally people do this using asm volatile with memory in the clobber list, but you sometimes see just asm volatile or just a plain asm clobbering memory. What impact do these different statements have on code generation (particularly in GCC, as it's unlikely to be portable)? Just for reference, these are the interesting variations: asm (""); // presumably this has no effect on code generation asm volatile (""); asm ("" ::: "memory"); asm volatile ("" ::: "memory");