solved a problem about undefined / unresolved reference in c
来源:互联网 发布:suse linux配置ip 编辑:程序博客网 时间:2024/03/29 06:10
//test.c
extern int a;
static int f(){
return a;
}
//main.c
static int a=20;
int main(){
return 0;
}
There will be no problem compiling this code,in msvc. In fact f() refereced a variable a defined staticly in main,c .because there is no other functions calling f(), it won't be linked.
but if add g() to test.c
int g(){
return f();
}
then msvc and intel c++ complains ahout undefined reference, because f is called by g, and g is used externally.
if we add static defination to g,then it still works. because g is used only in test.c,and no other functions called g, so it won;t be linked too.
if using c++ builder compiler, it is even not a problem if g is a non static function, as long as there is no other compile unit called g.
under gcc, even static functions not using by any other functions will be linked. so the above code will generate an underfined error. the only exception is that if the function is decoration by static inline. but as we know inline functions is not always being inlined. such as belows:
static inline int f(){
return a;
}
int (*delegate)()=f;
because a function referenced by a function pointer can not be inlined, so the above code can not be linked either.
- solved a problem about undefined / unresolved reference in c
- A problem that solved in a formal method-Modelchecking
- Unsolved problem about ant(Solved now!)
- How I solved a problem about usage of pscp by requesting more information
- cf#320 Div.2 Problem C A Problem about Polyline
- cf#320 Div.2 Problem C A Problem about Polyline
- java.lang.Error: Unresolved compilation problem: Cannot make a static reference to the non-static
- A Problem I Solved Last Night
- Is Query Optimization a “Solved” Problem?
- A Quiz About Integers in C
- A Quiz About Integers in C
- [Solved]Find a Child in a QTreeView
- My first blog!! About a problem in SQL 2005 configuration...
- A problem about printf
- A problem about Autoinvoice
- A problem about date
- A Problem about Polyline
- Codeforces Round #320 (Div. 2)C. A Problem about Polyline
- Const 的使用
- 第六課 笑顔(成田、吉森)
- 认识XML Schema 是怎么一回事
- 央视报道69批次婴儿奶粉含三聚氰胺(含名单)
- 《Win32 多线程程序设计》读书笔记
- solved a problem about undefined / unresolved reference in c
- 在MAC平台上 使用SDL 把SDL窗口加入子窗口中
- C#数值编辑控件TNumEditBox(C# Numerical/Decimal Edit Control)
- 无题
- 心情好爽!!
- 概要设计心得
- 关于EXTJS的tree的应用的几点心得
- 安装CVSTrac/SVNTrac
- 九月十七日 多云