函数在c99中隐式声明无效

We are very much familiar with the flow control in C where it follows the Top-Down approach, and when we are writing a C program and if we are using any function, we might have come across a very common error ‘Implicit declaration of function’.

我们非常熟悉C中遵循自顶向下方法的流控制,并且当我们编写C程序并且使用任何函数时,我们可能会遇到一个非常常见的错误“函数的隐式声明” '。

Now why this error occurred? The answer is already in the error.

现在为什么会发生此错误? 答案已经在错误中。

We have used a function in our program which is not declared yet or we can say that we have used a function implicitly.

我们在程序中使用了尚未声明的函数,或者可以说我们隐式使用了函数。

Implicit declaration of the function is not allowed in C programming. Every function must be explicitly declared before it can be called.

C编程中不允许隐式声明函数。 必须先明确声明每个函数,然后才能调用它。

In C90, if a function is called without an explicit declaration, the compiler is going to complain about the implicit declaration.

在C90中,如果在没有显式声明的情况下调用函数,则编译器将抱怨隐式声明。

Here is a small code that will give us an Implicit declaration of function error.

这是一个小代码,它将为我们提供函数错误的隐式声明。

#include <stdio.h>int main(void) {int a = 10;int b = 20;printf("The value of %d + %d is %d",a, b, addTwo(10, 20));return 0;
}

Now the above code will give you an error of Implicit declaration.

现在,上面的代码将给您一个隐式声明错误。

clang-7 -pthread -lm -o main main.c
main.c:6:45: warning: implicit declaration of function'addTwo' is invalid in C99[-Wimplicit-function-declaration]printf("The value of %d + %d is %d",a, b, addTwo(10...^
1 warning generated.
/tmp/main-c6e933.o: In function `main':
main.c:(.text+0x38): undefined reference to `addTwo'
clang-7compiler exit status 1
: error: linker command failed with exit code 1 (use -v to see invocation)

Here are some of the reasons why this is giving error.

这是造成错误的一些原因。

  1. Using a function that is pre-defined but you forget to include the header file for that function.使用预定义的功能,但是您忘记包含该功能的头文件。
  2. If you are using a function that you have created but you failed to declare it in the code. It’s better to declare the function before the main.如果使用的是已创建的函数,但未能在代码中声明它。 最好在main之前声明该函数。

In C90, this error can be removed just by declaring your function before the main function.

在C90中,只需在主函数之前声明您的函数即可消除此错误。

For example:

例如:

#include <stdio.h>
int yourFunctionName(int firstArg, int secondArg);int main() {
// your code here
// your function call
}int yourFunctionName(int firstArg, int secondArg) {
// body of the function
}

In the case of C99, you can skip the declaration but it will give us a small warning and it can be ignored but the definition of the function is important.

在C99的情况下,可以跳过该声明,但是会给我们一个小的警告,可以忽略它,但是函数的定义很重要。

#include <stdio.h>
// optional declaration
int main(void) {int a = 10;int b = 20;printf("The value of %d + %d is %d",a, b, addTwo(10, 20));return 0;
}int addTwo(int a, int b) {return a + b;
}

This gives us the output:

这给了我们输出:

clang-7 -pthread -lm -o main main.c
main.c:6:45: warning: implicit declaration of function'addTwo' is invalid in C99[-Wimplicit-function-declaration]printf("The value of %d + %d is %d",a, b, addTwo(10...^
1 warning generated.
./main
The value of 10 + 20 is 30

Here you can see that our code is working fine and a warning is generated but we are good to go but this is not recommended.

在这里,您可以看到我们的代码运行正常,并生成了警告,但是我们很高兴这样做,但是不建议这样做

Well, this was all about the Implicit declaration of the function in C and the error related to it. If you stuck into any kind of error, don’t forget to google it and try to debug it on your own. This will teach you how to debug on your own as someone might have faced a similar problem earlier.

好吧,这全都与C中函数的隐式声明以及与之相关的错误有关。 如果您遇到任何类型的错误,请别忘了用Google搜索并尝试自行调试。 这将教您如何自行调试,因为之前可能有人遇到过类似的问题。

If you still don’t find any solution for your problem, you can ask your doubt in the comment’s section below and we’ll get back to you

函数在c99中隐式声明无效_C函数的隐式声明相关推荐

  1. 【C 语言】结构体 ( 结构体类型定义 | 结构体类型别名 | 声明结构体变量的三种方法 | 栈内存中声明结构体变量 | 定义隐式结构体时声明变量 | 定义普通结构体时声明变量 )

    文章目录 一.结构体类型定义 二.结构体类型别名 三.结构体类型变量声明 1.使用结构体类型 ( 别名 ) 声明变量 2. 定义隐式结构体时声明变量 3.定义普通结构体时声明变量 二.完整代码示例 一 ...

  2. C++---显示实例化与隐式实例化,显示调用与隐式调用

    出现场景:C++模板中 template<class T> T Add(T left,T right)return left+right; 上述代码只有经过实例化之后才会形成真正的函数,没 ...

  3. sql隐式转换_SQL Server中的隐式转换

    sql隐式转换 This article will provide an overview of SQL Server implicit conversion including data type ...

  4. 析构函数声明无效_C++基类的析构函数为何要声明为虚函数

    C++的类中,构造函数用于初始化对象及相关操作,构造函数是不能声明为虚函数的,因为在执行构造函数前对象尚未完成创建,虚函数表还不存在. 析构函数用于销毁对象完成时相应资源的释放工作,析构函数可以被声明 ...

  5. oracle隐式转换能禁用吗,Oracle隐式转换

    和其他的关系型数据库一样, oracle 中也能进行一些隐式的数据转换,这对我们写 SQL 语句有 非常 用,我们可以不必麻烦地手动转化很多类型的字符.虽然前面我们介绍了一些使用例如to_char,t ...

  6. php隐式转换,隐式转换如何使用?总结隐式转换实例用法

    JavaScript的数据类型分为六种,分别为null,undefined,boolean,string,number,object.object是引用类型,其它的五种是基本类型或者是原始类型.我们可 ...

  7. Android 隐式跳转(Activity的隐式跳转)

    学而时习之,温故而知新,放假前回顾下android 的 隐式跳转 Activity的显式跳转: 是直接指定需要调用的Activity Activity的隐式跳转: 不明确指定启动哪个Activity, ...

  8. 隐式链接隐式链接_在木材上隐式标签选择

    隐式链接隐式链接 I assume every Android developer knows and uses the logging facilities provided by the Andr ...

  9. c语言 隐式声明,关于C#:隐式函数声明和链接

    最近,我了解了C语言中的隐式函数声明.主要思想很明确,但在这种情况下,我对理解链接过程有些麻烦. 考虑以下代码(文件a.c): #include int main() { double someVal ...

  10. 函隐式声明函数是什么意思

    由于编译器在处理函数调用代码时没有找到函数原型,只好根据函数调用代码做隐式声明. 为什么编译器在处理函数调用代码时需要有函数原型?因为必须知道参数的类型和个数以及返回值的类型才知道生成什么样的指令.为 ...

最新文章

  1. 窗体的常用属性和常用事件
  2. scala 数据类型体系一览图
  3. 计算机免修考试题库,计算机免修考试内容和样卷.doc
  4. P3356 火星探险问题(网络流)
  5. 线性代数向量内积_向量的外积| 使用Python的线性代数
  6. 100级大橙武升级流程_DNF:女气功升级100级无暇手套,前后伤害对比。
  7. Windows下使用taskkill 命令批量结束进程
  8. Linux系统管理系列(1)——文件管理权限详解 chgrp chown chmod rwx等等
  9. python游戏设计毕业论文_游戏毕业设计论文
  10. mbot机器人自动超声波模式程序_测评 | mBot机器人秒变编程达人
  11. 天梯赛 L2-001 紧急救援 (25 分)详细注释
  12. JSP设置网站favicon.ico
  13. 【矩阵论】线性空间与线性变换(5)
  14. 使用Quads绘制函数曲线
  15. 手动添加打印机的方法(hp laserjet p2055dn为例)
  16. C语言中在常数后面加U、L、F的功能(转)
  17. malloc函数未定义
  18. 什么叫五口POE交换机 五口POE交换机使用方法
  19. 联发科的原厂芯片资料下载?那里有这些资料?最全的资料整理在这里
  20. 用计算机程序解决问题的核心是什么,1.1使用计算机解决问题的一般过程

热门文章

  1. 从fit文件中提取lick指数的matlab程序
  2. Hi,你有一封来自 Googlers 的邀约
  3. 2.Java语言基础——流程控制语句与方法
  4. pod容器发生OOM错误(by quqi99)
  5. ubuntu18.04安装OpenCV3.4.12步骤及安装中遇到的一些问题
  6. 01_Snaker简介
  7. PRT电波拉皮的原理, 做电波拉皮效果好吗能维持多久
  8. 被华策、欢瑞等甩下,唐人影视往日荣光已成回忆?
  9. java调用高德地图api_JAVA调用高德地图API实践
  10. Mac Android Studio Flutter环境配置之第一个Futter项目