warning: return type defaults to ‘int’ [-Wreturn-type]

五迷三道 提交于 2019-11-27 23:33:54
main()

should be

int main()

In C89, the default return type is assumed to be int, that's why it works.

In C89, the default return type is int. This default was removed in C99 and compilers are helpful reminding you that your C-style with no int before main() is out of date.

See the C89 specification Section 3.5.2 "Type specifiers":

  • "Each list of type specifiers shall be one of the following sets: [...] + int, signed, signed int, or no type specifiers".

  • And in the second paragraph of semantics: "Each of the [...] sets designates the same type, except that for bit-fields [blabla]". So this means "no type specifiers" is the same as int.

In C99, the part "or no type specifier" is removed. (But you can still write signed without the int part.)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!