简体   繁体   English

lang c99的主要功能

[英]the main function in clang c99

In c99 standard, main function can be defined in two styles: 在c99标准中,主要功能可以用两种样式定义:

int main(void)

or 要么

int main(int argc, char \* argv[])

But I tried (llvm 8 c99(-std=c99)) 但是我尝试了(llvm 8 c99(-std = c99))

int main()/main()

and there is no warning or error. 并且没有警告或错误。

How to understand the main definition in c99. 如何理解c99中的main定义。 and where to find the whole definition types of main function in clang? 在哪里可以找到clang main功能的整个定义类型?

There is int type is default for cases where it is omited. 对于被忽略的情况,默认为int类型。 And for function return type too. 并且对于函数返回类型也是如此。 The void type for funtion args is equal that function have no arguments. 函数args的void类型等于该函数没有参数。 The empty args '()' mean that arguments and its count and its types is not specicfied. 空参数'()'表示未指定参数及其计数和类型。

Due to historical reasons, most compilers do not warn for int main() or just main() -- because that's how main() has been mostly before standardization of C. 由于历史原因,大多数编译器不会警告int main()或仅警告main() ,因为那是main()在C标准化之前的主要方式。

GCC has some warning options which can detect it. GCC有一些警告选项可以检测到它。

For main() : 对于main()

$ gcc -Wall -Wextra -Wold-style-declaration  -Wold-style-definition -Wstrict-prototypes -std=c99 test.c
test.c:4:1: warning: return type defaults to ‘int’ [-Wimplicit-int]
 main()
 ^~~~
test.c:4:1: warning: function declaration isn’t a prototype [-Wstrict-prototypes]
test.c: In function ‘main’:
test.c:4:1: warning: old-style function definition [-Wold-style-definition]

and for int main() : 对于int main()

$ gcc -Wall -Wextra -Wold-style-declaration  -Wold-style-definition -Wstrict-prototypes -std=c99 test.c
test.c:4:5: warning: function declaration isn’t a prototype [-Wstrict-prototypes]
 int main()
     ^~~~
test.c: In function ‘main’:
test.c:4:5: warning: old-style function definition [-Wold-style-definition]

There has been a bug report in llvm whichg seems to have fixed this very recently. llvm中有一个错误报告 ,g似乎已经解决了这一问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM