我这么问是因为我的编译器似乎是这么认为的,尽管我并不这么认为。
echo 'int main;' | cc -x c - -Wall
echo 'int main;' | c++ -x c++ - -Wall
Clang issues no warning or error with this, and gcc issues only the meek warning: 'main' is usually a function [-Wmain]
, but only when compiled as C. Specifying a -std=
doesn’t seem to matter.
否则,它可以很好地编译和链接,但是在执行时,它会立即以 SIGBUS
结束(对我来说)。
Reading through the (excellent) answers at Main ()在 C 和 C + + 中应该返回什么? and a quick grep through the language specs, it would certainly 看起来 to me that a main 功能 is required. But the verbiage from gcc’s -Wmain
(‘main’ is 通常 a function) (and the dearth of errors here) seems to possibly suggest otherwise.
但是为什么呢? 是否有一些奇怪的边缘情况或“历史”用于这个? 有人知道什么给?
我的观点,我想,是我真的认为这应该是一个在托管环境中的 错误,嗯?