关于GCC内联汇编奇怪的错误信息

关于GCC内联汇编奇怪的错误信息

问题描述:

int main()
{
    __asm__("movl $0x1,%%eax;
            movl $0x0,%%ebx;
            int $0x80;
            ":::"eax","ebx");
}

我尽量模拟的exit()在Linux中的行为。但在现代的Linux,我觉得这是很难做到的,既然有些退出处理程序将退出后,被称为()。
所以我写一个老版本的退出()。也许10年前,你可以在某些codeS中找到它。
我用gcc编译。

I try to simulate the behavior of exit() in Linux. But in modern Linux I find it's very difficult to do that since some exit handlers will be called after exit(). So I write an old version of exit(). Maybe 10 years ago you can find it in some codes. I compile it with gcc.

gcc -o exit exit.c

和它给了我这些消息。

exit.c: In function ‘main’:
exit.c:3:13: warning: missing terminating " character [enabled by default]
exit.c:3:5: error: missing terminating " character
exit.c:4:13: error: expected string literal before ‘movl’
exit.c:6:27: warning: missing terminating " character [enabled by default]
exit.c:6:13: error: missing terminating " character

我已经仔细检查了我的code和我不认为我的code是错误的。所以,那是什么?

I have carefully examined my code and I don't think my code is wrong. So what is that?

您已经不能嵌入引用的字符串内换行

You cannot have embedded newlines inside quoted strings

// bad
"two
lines"

重写为

// good
"two\n"
"lines"

在preprocessor将加入串无缝结合,以

The preprocessor will join the strings seamlessly, to

"two\nlines"