繁体   English   中英

lang c99的主要功能

[英]the main function in clang c99

在c99标准中,主要功能可以用两种样式定义:

int main(void)

要么

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

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

int main()/main()

并且没有警告或错误。

如何理解c99中的main定义。 在哪里可以找到clang main功能的整个定义类型?

对于被忽略的情况,默认为int类型。 并且对于函数返回类型也是如此。 函数args的void类型等于该函数没有参数。 空参数'()'表示未指定参数及其计数和类型。

由于历史原因,大多数编译器不会警告int main()或仅警告main() ,因为那是main()在C标准化之前的主要方式。

GCC有一些警告选项可以检测到它。

对于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]

对于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]

llvm中有一个错误报告 ,g似乎已经解决了这一问题。

暂无
暂无

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

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