c - 警告 : return type defaults to ‘int’ [-Wreturn-type]

标签 c compiler-warnings

我是一名开始学习 C 的 Linux 用户,我正在尝试编译我输入的源代码:

#include <stdio.h>
main()
{
        float c,d;
        c = 10215.3;
        d = c / 3;
        printf("%3.2f\n",d);
        return 0;
}

它使用我编写的 makefile 编译:

cc -Wall -g     printf.c   -o printf

但我收到此警告:

printf.c:2:1: warning: return type defaults to ‘int’ [-Wreturn-type]

它编译代码,我得到了想要的输出,但我想了解这意味着什么

最佳答案

main()

应该是

int main()

在 C89 中,默认返回类型被假定为 int,这就是它起作用的原因。

关于c - 警告 : return type defaults to ‘int’ [-Wreturn-type],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12373538/

相关文章:

c++ - GCC: "__unused__"与变量属性中的 "unused"

compiler-errors - 简单 C 语法中的移位/减少冲突

C 程序 - printf 与其他 printf 字符重叠

c - 如何解决此编译器警告的原因?

c - 字符串的插入排序(降序)

c - 如何抑制阴影 "index"警告?

c - 打印出编译时计算的常量的方法

c - 用于附加字符串的 sprintf vs strcat

C# 编译器警告 1685

scala - 如何避免 'Non-variable type argument is unchecked since it is eliminated by erasure' ?