A question about "memory" clobbers in asm

Ian Lance Taylor ian@wasabisystems.com
Fri Sep 17 15:39:00 GMT 2004


Jamie Lokier <jamie@shareable.org> writes:

Should this be on gcc-help?

> I'm having trouble understand when it's appropriate to use a "memory"
> clobber, when to use volatile, and when to use both.  The manual is
> unclear to me.  Although I see that someone has tried to clarify it
> since I last read it, it's still not obvious how "memory" is different
> from `volatile'.

Volatile means that the assembler instruction can not be deleted, even
if it appears to be useless.

Marking the instruction as clobbering memory means that if the
instruction is executed, then memory is clobbered in some undescribed
way.  However, that clobbering is not important to proper execution of
the program, and the instruction can be deleted if the specified
side-effects turn out to be unnecessary.

At least, that is my understanding.

Ian



More information about the Gcc mailing list