gpt4 book ai didi

c - 粘贴 ""Pushl $""和 ""1 5""时出错,未给出有效的预处理 token

转载 作者:行者123 更新时间:2023-11-30 17:08:36 24 4
gpt4 key购买 nike

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

源文件

#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 $0xceafbeef,%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 $0x21,%al\n\t" \
"orb $1<<"##x",%al\n\t" \
"outb %al,$0x21\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 $0xceafbeef,%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 $0xa1,%al\n\t" \
"orb $1<<("##x"-8),%al\n\t" \
"outb %al,$0xa1\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   $1<<"" and ""5"" does not give a
valid preprocessing token
"orb $1<<"##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 $1<<"" and ""6"" does not give a
valid preprocessing token
"orb $1<<"##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 $1<<"" and ""7"" does not give a
valid preprocessing token
"orb $1<<"##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 $1<<("" and ""8"" does not give a
valid preprocessing token
"orb $1<<("##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" 是两个标记。

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

关于c - 粘贴 ""Pushl $""和 ""1 5""时出错,未给出有效的预处理 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33585558/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com