Mail Archives: djgpp/2000/06/21/08:34:42
On Wed, 21 Jun 2000 pavenis AT lanet DOT lv wrote:
> > AFAIK, inline assembly doesn't go through cpp; GCC emits it in the
> > form of preprocessed assembly. So you cannot have any preprocessor
> > directives inside the asm() block.
>
> Wrong.
>
> There are no problems using #ifdef and similar stuff inside inline
> assembler. Inline assembler is normally recognised by cc1 or cc1plus
> so it's only after cpp have processed file.
This is a misunderstanding: what I meant to say was that the inline
assembly doesn't go through preprocessor *after* cc1 or cc1plus wrote it
to the output, i.e. between cc1 and Gas.
It goes without saying that the C/C++ source itself goes through
preprocessor. But at that stage, the asm is not interpreted except for
constraints and clobber lists.
> #define TEST
> #define FOO "inc %%eax"
>
> int main (void)
> {
> int foo = 1;
> asm ( "inc %%eax\t\n"
> "inc %%eax\t\n"
> #ifdef TEST
> "inc %%eax\t\n"
> #endif
> FOO "\t\n"
> : "=a" (foo)
> : "a" (foo)
> );
> return foo;
> }
In this example, the preprocessor directives are on the C level, not on
the assembly level. To be on assembly level, they would need to be
inside the quoted assembly code, not outside it.
I'm sorry if my wording was unclear.
- Raw text -