inline labels

Dave Klint davek@ca.mgisoft.com
Wed May 24 18:01:00 GMT 2000


> > When compiling using the -O3, gcc will decide that some functions
> > can be inlined and expands them.  This is all well and good, but
> > when there's an asm() statement in the function with a label in
> > it, it causes the label to be defined more than once.  Is there
> > any way around this without reworking the assembly?
> 
> The GCC manual talks about local labels in assembly statements.  You
> may also look for `%='; it's described in the section about output
> templates; I'm not sure it can be used in asm statements, though.

Just thought I'd post the answer to my own question, there are a lot
of other '%' things then I thought.  I checked the gnu docs at gnu.org
( http://gcc.gnu.org/onlinedocs/gcc_16.html#SEC179 ) and found out 
everything that I ever wanted to know about templates.  I checked the
docs before asking the question, but I guess I just didn't check
well enough.  The '%=' does give you a unique number that you can
use in the inline assembly labels.  For example

asm("movl foo,%eax
.Lfoo%=:
     incl %eax
     jc .Lfoo%="
);

works just fine, and things don't get clobbered when you let gcc
optimize.  Gcc rocks, that all I gotta say.

-dave


More information about the Gcc-help mailing list