错误粘贴“"pushl $"”和“15”没有提供有效的预处理标记

error pasting ""pushl $"" and ""15"" does not give a valid preprocessing token

我在尝试编译此源代码时遇到了这个烦人的错误,但我不知道为什么会出现这些错误。我已经搜索过了,但没有找到任何有用的东西。

源文件

#include <ddk/ntddk.h>
#include <internal/ntoskrnl.h>
#include <internal/ke.h>
#include <internal/i386/segment.h>


#define _STR(x) #x
#define STR(x) _STR(x)


#define IRQ_HANDLER_FIRST(x,y)  \
      void irq_handler_##y (void);   \
       __asm__("\n\t.global _irq_handler_"##x"\n\t_irq_handler_"##x":\n\t" \
        "pusha\n\t"                     \
        "pushl %ds\n\t"                 \
        "pushl %es\n\t"                 \
        "pushl %fs\n\t"                  \
        "movl  [=11=]xceafbeef,%eax\n\t"      \
        "pushl %eax\n\t"                \
        "movw  $"STR(KERNEL_DS)",%ax\n\t"       \
        "movw  %ax,%ds\n\t"             \
        "movw  %ax,%es\n\t"             \
        "inb   [=11=]x21,%al\n\t"               \
        "orb   <<"##x",%al\n\t"       \
        "outb  %al,[=11=]x21\n\t"               \
        "pushl %esp\n\t"                \
        "pushl $"##x"\n\t"              \
        "call  _KiInterruptDispatch\n\t"\
        "popl  %eax\n\t"                \
        "popl  %eax\n\t"                \
        "popl  %eax\n\t"                \
        "popl  %fs\n\t"                 \
        "popl  %es\n\t"                 \
        "popl  %ds\n\t"                 \
        "popa\n\t"                      \
        "iret\n\t")

#define IRQ_HANDLER_SECOND(x,y)  \
      void irq_handler_##y (void);   \
       __asm__("\n\t.global _irq_handler_"##x"\n\t_irq_handler_"##x":\n\t" \
        "pusha\n\t"                     \
        "pushl %ds\n\t"                 \
        "pushl %es\n\t"                 \
        "pushl %fs\n\t"                 \
        "movl  [=11=]xceafbeef,%eax\n\t"      \
        "pushl %eax\n\t"                \
        "movw  $"STR(KERNEL_DS)",%ax\n\t"       \
        "movw  %ax,%ds\n\t"             \
        "movw  %ax,%es\n\t"             \
        "inb   [=11=]xa1,%al\n\t"               \
        "orb   <<("##x"-8),%al\n\t"       \
        "outb     %al,[=11=]xa1\n\t"               \
        "pushl %esp\n\t"                \
        "pushl $"##x"\n\t"              \
        "call  _KiInterruptDispatch\n\t"\
        "popl  %eax\n\t"                \
        "popl  %eax\n\t"                \
        "popl  %eax\n\t"                \
        "popl  %fs\n\t"                 \
        "popl  %es\n\t"                 \
        "popl  %ds\n\t"                 \
        "popa\n\t"                      \
        "iret\n\t")


IRQ_HANDLER_FIRST ("0",0);
IRQ_HANDLER_FIRST ("1",1);
IRQ_HANDLER_FIRST ("2",2);
IRQ_HANDLER_FIRST ("3",3);
IRQ_HANDLER_FIRST ("4",4);
IRQ_HANDLER_FIRST ("5",5);
IRQ_HANDLER_FIRST ("6",6);
IRQ_HANDLER_FIRST ("7",7);
IRQ_HANDLER_SECOND ("8",8);
IRQ_HANDLER_SECOND ("9",9);
IRQ_HANDLER_SECOND ("10",10);
IRQ_HANDLER_SECOND ("11",11);
IRQ_HANDLER_SECOND ("12",12);
IRQ_HANDLER_SECOND ("13",13);
IRQ_HANDLER_SECOND ("14",14);
IRQ_HANDLER_SECOND ("15",15);

然后我得到类似的东西

ke/i386/irqhand.c:25:9: error: pasting ""orb   <<"" and ""5"" does not give a
valid preprocessing token
         "orb   <<"##x",%al\n\t"       \
         ^
ke/i386/irqhand.c:72:1: note: in expansion of macro 'IRQ_HANDLER_FIRST'
 IRQ_HANDLER_FIRST ("5",5);
 ^
ke/i386/irqhand.c:28:9: error: pasting ""pushl $"" and ""5"" does not give a val
id preprocessing token
         "pushl $"##x"\n\t"              \
         ^
ke/i386/irqhand.c:72:1: note: in expansion of macro 'IRQ_HANDLER_FIRST'
 IRQ_HANDLER_FIRST ("5",5);
 ^
ke/i386/irqhand.c:14:16: error: pasting ""\n\t.global _irq_handler_"" and ""6""
does not give a valid preprocessing token
        __asm__("\n\t.global _irq_handler_"##x"\n\t_irq_handler_"##x":\n\t" \
                ^
ke/i386/irqhand.c:73:1: note: in expansion of macro 'IRQ_HANDLER_FIRST'
 IRQ_HANDLER_FIRST ("6",6);
 ^
ke/i386/irqhand.c:14:46: error: pasting ""\n\t_irq_handler_"" and ""6"" does not
 give a valid preprocessing token
        __asm__("\n\t.global _irq_handler_"##x"\n\t_irq_handler_"##x":\n\t" \
                                              ^
ke/i386/irqhand.c:73:1: note: in expansion of macro 'IRQ_HANDLER_FIRST'
 IRQ_HANDLER_FIRST ("6",6);
 ^
ke/i386/irqhand.c:25:9: error: pasting ""orb   <<"" and ""6"" does not give a
valid preprocessing token
         "orb   <<"##x",%al\n\t"       \
         ^
ke/i386/irqhand.c:73:1: note: in expansion of macro 'IRQ_HANDLER_FIRST'
 IRQ_HANDLER_FIRST ("6",6);
 ^
ke/i386/irqhand.c:28:9: error: pasting ""pushl $"" and ""6"" does not give a val
id preprocessing token
         "pushl $"##x"\n\t"              \
         ^
ke/i386/irqhand.c:73:1: note: in expansion of macro 'IRQ_HANDLER_FIRST'
 IRQ_HANDLER_FIRST ("6",6);
 ^
ke/i386/irqhand.c:14:16: error: pasting ""\n\t.global _irq_handler_"" and ""7""
does not give a valid preprocessing token
        __asm__("\n\t.global _irq_handler_"##x"\n\t_irq_handler_"##x":\n\t" \
                ^
ke/i386/irqhand.c:74:1: note: in expansion of macro 'IRQ_HANDLER_FIRST'
 IRQ_HANDLER_FIRST ("7",7);
 ^
ke/i386/irqhand.c:14:46: error: pasting ""\n\t_irq_handler_"" and ""7"" does not
 give a valid preprocessing token
        __asm__("\n\t.global _irq_handler_"##x"\n\t_irq_handler_"##x":\n\t" \
                                              ^
ke/i386/irqhand.c:74:1: note: in expansion of macro 'IRQ_HANDLER_FIRST'
 IRQ_HANDLER_FIRST ("7",7);
 ^
ke/i386/irqhand.c:25:9: error: pasting ""orb   <<"" and ""7"" does not give a
valid preprocessing token
         "orb   <<"##x",%al\n\t"       \
         ^
ke/i386/irqhand.c:74:1: note: in expansion of macro 'IRQ_HANDLER_FIRST'
 IRQ_HANDLER_FIRST ("7",7);
 ^
ke/i386/irqhand.c:28:9: error: pasting ""pushl $"" and ""7"" does not give a val
id preprocessing token
         "pushl $"##x"\n\t"              \
         ^
ke/i386/irqhand.c:74:1: note: in expansion of macro 'IRQ_HANDLER_FIRST'
 IRQ_HANDLER_FIRST ("7",7);
 ^
ke/i386/irqhand.c:41:16: error: pasting ""\n\t.global _irq_handler_"" and ""8""
does not give a valid preprocessing token
        __asm__("\n\t.global _irq_handler_"##x"\n\t_irq_handler_"##x":\n\t" \
                ^
ke/i386/irqhand.c:75:1: note: in expansion of macro 'IRQ_HANDLER_SECOND'
 IRQ_HANDLER_SECOND ("8",8);
 ^
ke/i386/irqhand.c:41:46: error: pasting ""\n\t_irq_handler_"" and ""8"" does not
 give a valid preprocessing token
        __asm__("\n\t.global _irq_handler_"##x"\n\t_irq_handler_"##x":\n\t" \
                                              ^
ke/i386/irqhand.c:75:1: note: in expansion of macro 'IRQ_HANDLER_SECOND'
 IRQ_HANDLER_SECOND ("8",8);
 ^
ke/i386/irqhand.c:52:9: error: pasting ""orb   <<("" and ""8"" does not give a
 valid preprocessing token
         "orb   <<("##x"-8),%al\n\t"       \
         ^
ke/i386/irqhand.c:75:1: note: in expansion of macro 'IRQ_HANDLER_SECOND'
 IRQ_HANDLER_SECOND ("8",8);
 ^
ke/i386/irqhand.c:55:9: error: pasting ""pushl $"" and ""8"" does not give a val
id preprocessing token
         "pushl $"##x"\n\t"              \
         ^
ke/i386/irqhand.c:75:1: note: in expansion of macro 'IRQ_HANDLER_SECOND'
 IRQ_HANDLER_SECOND ("8",8);
 ^
ke/i386/irqhand.c:41:16: error: pasting ""\n\t.global _irq_handler_"" and ""9""
does not give a valid preprocessing token
        __asm__("\n\t.global _irq_handler_"##x"\n\t_irq_handler_"##x":\n\t" \
                ^
ke/i386/irqhand.c:76:1: note: in expansion of macro 'IRQ_HANDLER_SECOND'
 IRQ_HANDLER_SECOND ("9",9);
 ^

如何解决这个问题?

去掉宏定义中的##。在这种情况下,它们是不必要且非法的。由于错误指示 ## 运算符的结果必须是单个有效的预处理标记,而 "pushl $""6" 是两个标记。

如果没有 ##,预处理器将不会尝试将两个字符串粘贴在一起以形成单个标记。它们将保留为单独的字符串标记,将在稍后的翻译阶段合并在一起。