This old-style function definition is not preceded by a prototype

Intro

在 Xcode 14 中随意写了几个C命令行程序,编译运行OK。
但是有以下两种报错:

This old-style function definition is not preceded by a prototype
This function declaration is not a prototype

解决方式见 SOF How to prevent error : this old-style function definition is not preceded by a prototype
在这里插入图片描述adding void in the parentheses helps me eliminate the warning
在圆括号里加void可以避免出现该warning。

对那些没有参数的函数,在其小括号中加一个void即可。

warning 及解决 截屏

在这里插入图片描述
在这里插入图片描述

//
//  main.c
//  function-learn
//
//  Created by wuyujin1997 on 2023/1/22.
//

#include <stdio.h>

void foo() {
    printf("foo\n");
}

void bar();

int main(int argc, const char * argv[]) {
    
    foo();
    bar();
    
    return 0;
}


void bar() {
    printf("bar\n");
}

知其然,却不知其所以然

问题解决了。
其实这两行warning的解决方式很容易就能查到。
可是为什么会出现该warning以及为什么加 void 可以避免出现该 warning,我依旧不知道。

先列一下猜想:

  • 对于无参函数的圆括号内的写法,是什么都不写,还是只写一个 void , 应该都是对的。但是区别是在不同的C语言标准下。
  • 使用的C语言编译器的种类加版本影响。

我的 Xcode 14 中使用的 C语言编译器是: Apple clang version 14.0.0 (clang-1400.0.29.202)

wuyujin1997@mac11 ~ % cc --version
Apple clang version 14.0.0 (clang-1400.0.29.202)
Target: arm64-apple-darwin22.2.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
wuyujin1997@mac11 ~ % 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值