1

我经历了各种各样的 quine 问题,但我的任务是在没有 quine 的情况下得到一个 quine 问题main(),并且循环也被禁止。

没有循环,这很容易,但我不知道如何在没有main(). 任何人都可以帮助我或提供链接吗?

4

3 回答 3

3

您不能创建没有main()函数的(非独立的)C 程序。main()因此,在通常意义上,在没有 a 的情况下在 C 中创建一个 quine是不可能的。

也就是说,根据您定义 quine 的方式,您可能能够构建无法编译的源文件,但编译错误(在某个特定编译器上)是源文件的内容。

于 2011-02-21T10:23:56.617 回答
1

First thing its impossible to write program without main function because compiler always starts execution from main() function, without main function linker will not be aware of start of data segment.

Yeah but playing with some tricks with preprocessor you can do it, but this is not a good method to do that.

http://www.gohacking.com/2008/03/c-program-without-main-function.html

This might help you.

Take a look here too:

Is a main() required for a C program?

于 2011-02-21T10:50:44.240 回答
0
#include <stdio.h>

int
foo(void) {
        printf("pong!\n");
        return 0;
}

int main() __attribute__((weak, alias("foo")));

有 main() 声明,但没有定义。

于 2011-02-21T10:40:12.237 回答