From: korpela AT albert DOT ssl DOT berkeley DOT edu (Eric J. Korpela) Newsgroups: comp.os.msdos.djgpp Subject: Re: Optimization and Inline ASM Date: 4 Oct 1996 23:22:45 GMT Organization: Cal Berkeley-- Space Sciences Lab Lines: 61 Message-ID: <534685$3ci@agate.berkeley.edu> References: <199610040234 DOT TAA04831 AT bluesky DOT com> NNTP-Posting-Host: albert.ssl.berkeley.edu To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp In article <199610040234 DOT TAA04831 AT bluesky DOT com>, Kevin Baca wrote: >> c:/djgpp/tmp\cccaaaaa:66: Fatal error:Symbol loc1 already defined. >> >> This error only occurs if I use the optimize switch: >> >> gcc myfile.cpp -O3 >> >> Compiles flawlessly if I use just: >> >> void myproc() >> { >> __asm__ __volatile__(" >> [code] >> loc1:\n [code] >> loc2:\n [code] ); >> } >> >> What am I doing wrong? Help me, or I'll be bold soon! This error has driven >> me NUTS!!! > >Try using different labels. Not just different labels, local labels. When the -O3 switch gets used simple functions are compiled inline. What this means is that every place that myproc is called is replaced with the assembly code for the above function. If myproc() is called more than once in the code you end up with multiple locations labeled loc1 and loc2. Local labels are defined as : (for ex. 0:, 1:, 2:, etc.) So if loc1: and loc2: were replaced by 1: and 2: things would be fine, almost. The reason I said almost is that when you reference a local label you need to tell the assembler which direction to look for the label (forward or backward). To do this you append an "f" or a "b" to the label name when it is referenced. As a useless example... .global _mypause _mypause: pushl %ebp movl %esp,%ebp movl 8(%ebp),%ecx testl %ecx,%ecx jz 0f 1: decl %ecx jnz 1b 0: movl %ebp,%esp popl %ebp ret Eric -- Eric Korpela | An object at rest can never be korpela AT ssl DOT berkeley DOT edu | stopped. Click here for more info.