what is the difference between definition and declaration in c
A declaration introduces an identifier
and describes its type, be it a type, object, or function. A declaration is what
the compiler needs to accept references to that identifier. These are declarations:
extern int bar;
extern int g(int, int);
double f(int, double); // extern can be omitted for function declarations
class foo; // no extern allowed for class declarations
A definition actually instantiates/implements
this identifier. It's what the linker
needs in order to link references to those entities. These are definitions corresponding to the above declarations: [a definition allocate space for the identifier // myself]
int bar; [someone said it is not only a definition but also a declaration]
int g(int lhs, int rhs) {return lhs*rhs;}
double f(int i, double d) {return i+d;}
class foo {};
A definition can be used in the place of a declaration.
An identifier can be declared as often as you want. Thus, the following is legal in C and C++:
double f(int, double);
double f(int, double);
extern double f(int, double); // the same as the two above
extern double f(int, double);
However, it must be defined exactly once. If you forget to define something that's been declared and referenced somewhere, then the linker doesn't
know what to link references to and complains about a missing symbols. If you define something more than once, then the linker doesn't know which of
the definitions to link references to and complains about duplicated symbols.
[from website] http://stackoverflow.com/questions/1410563/what-is-the-difference-between-a-definition-and-a-declaration
what is the difference between definition and declaration in c的更多相关文章
- Definition vs declaration
#include <stdio.h> union test1; // declaration union test2 { // The definition of union test2 ...
- Relevance Between Variable Declaration and Definition in C++
A declaration makes a name known to a programm. A definition creates the assocatied entity. A variab ...
- Hibernate Validator 6.0.9.Final - JSR 380 Reference Implementation: Reference Guide
Preface Validating data is a common task that occurs throughout all application layers, from the pre ...
- SWIG 3 中文手册——5. SWIG 基础知识
目录 5 SWIG 基础知识 5.1 运行 SWIG 5.1.1 输入格式 5.1.2 SWIG 输出 5.1.3 注释 5.1.4 C 预处理器 5.1.5 SWIG 指令 5.1.6 解析限制 5 ...
- 在centos7(EL7.3 即 kernel-3.10.0-514.X )上安装BCM4312无线网卡驱动要注意的问题
我新装的centos7主机无法使用里面自带的网卡,查询后发现网卡型号为BCM4312.我在看资料安装的过程中遇到了些问题,纠结了好久,现在分享下要注意的点,为后来的遇到同样问题的人提供点帮助.现在开始 ...
- 【转】CentOS6.3安装Broadcom无线网卡驱动
转自: http://blog.csdn.net/jimanyu/article/details/9697833 下面是具体的步骤 一:确定无线网卡的型号,驱动下载 第一步要确定机子的无线网卡型号是什 ...
- clang format 官方文档自定义参数介绍(中英文)
官方文档:http://clang.llvm.org/docs/ClangFormatStyleOptions.html 中文 在代码中配置样式 当使用 clang::format::reformat ...
- [C/C++]C++声明
[注]本文是Declarations的翻译和注解版. https://msdn.microsoft.com/en-us/library/f432x8c6.aspx 1.声明: 我们通过声明往C++程序 ...
- C++ Variables and Basic Types Notes
1. Type conversion: If we assign an out-of-range value to an object of unsigned type, the result is ...
随机推荐
- GAN(Generative Adversarial Networks) 初步
1. Generator vs. Discriminator 首先需要指出的是生成式模型(generative models)和判别式模型(discriminative models)的区别: dis ...
- 【44.64%】【codeforces 743C】Vladik and fractions
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 将Sublime Text2 加入右键菜单
在googleread里面看有人推荐sublime text2.说开发很方便.就下载一个试试.写html还真的挺爽. 于是按照vim加入鼠标右键的方法.果然可以.这里和大家分享 1. 运行中输入 re ...
- Session or Cookie?是否需要用Tomcat等Web容器的Session
Cookie是HTTP协议标准下的存储用户信息的工具,浏览器把用户信息存放到本地的文本文件中. Session是基于Cookie实现的. 2011年4月,武汉群硕面试的时候(实习生),面试官也问过这个 ...
- 每天一个JavaScript实例-处理textarea中的字符成每一行
<!doctype html> <html lang="en"> <head> <meta charset="utf-8&quo ...
- Java程序猿的JavaScript学习笔记(5——prototype和Object内置方法)
计划按例如以下顺序完毕这篇笔记: Java程序猿的JavaScript学习笔记(1--理念) Java程序猿的JavaScript学习笔记(2--属性复制和继承) Java程序猿的JavaScript ...
- IT增值服务实践心得体会:企业客户的钱比个人客户好赚得多
友情提示 本人喜欢直言不讳,不喜欢拐弯抹角.喜欢从客观和主观.自身和他人等多种角度去探讨问题.如有不当之处,欢迎吐槽. 若干心得体会1.企业客户的钱更好赚,个人客户的钱很难. 为什么这么说呢? a. ...
- 【codeforces 765D】Artsem and Saunders
[题目链接]:http://codeforces.com/contest/765/problem/D [题意] 给你一个函数f(x); 要让你求2个函数g[x]和h[x],使得g[h[x]] = x对 ...
- eclipse使用Hibernate tools反向工程插件遇到的几个问题
1,在eclipse使用hibernate工具,生成hibernate配置文件时,可能会提示not parse ....xml错误 参见 加载本地dtd 2,反向工程中,生成配置文件时,一般要填写其默 ...
- scala读写文件 comparing values of types Unit and Int using `!=' will always yield true
由于scala没有对写入文件的支持,所以写文件时通常借助java进行IO操作 //方式一(小文件) /* val s1 = Source.fromFile("D:\\inputword\\h ...