相关疑难解决方法(0)


具有名为main的全局变量而不是main函数的程序如何工作?

考虑以下计划:

#include <iostream>
int main = ( std::cout << "C++ is excellent!\n", 195 ); 
Run Code Online (Sandbox Code Playgroud)

在Windows 7操作系统上使用g ++ 4.8.1(mingw64),程序编译并运行正常,打印:

C++非常棒!

到控制台.main似乎是一个全局变量而不是一个函数; 如果没有该功能,该程序如何执行main()?这段代码是否符合C++标准?程序的行为是否定义明确?我也使用了该-pedantic-errors选项,但该程序仍然编译并运行.

c++ program-entry-point language-lawyer

97
推荐指数
5
解决办法
9849
查看次数

如何在不使用任何函数的情况下在C中编写"Hello world"?

我找到了在quora上做到这一点的方法,但我无法理解.

You can achieve this using opcodes.....

const int main[] = {  -443987883, 440, 113408, -1922629632,  4149, 899584, 84869120, 15544,  266023168, 1818576901, 1461743468, 1684828783,  -1017312735};
Now follow below steps....
Save that in hello.c
then gcc -o hello hello.c
then ./hello
Hola..... Hello World!
Run Code Online (Sandbox Code Playgroud)

操作码将根据其架构特定于特定硬件和控制器.如果我理解正确,那么对于不同的硬件和平台,操作码将是不同的.所以这不是一般的解决方案.但是我试图在IDEone上编译它并且它给出了运行时错误.有没有通用的解决方案?

关于SE的类似问题

c assembly

-4
推荐指数
1
解决办法
167
查看次数