这种东西,不出错时完全不重要;一旦出错让人完全找不着北。
如果被调函数在单独的文件中定义,比如
function.c:
void myfun(int i) { //do something with i }
然后主函数文件中声明
main.c:
extern void myfun(int i); int main() { myfun(-1); return 0; }
这个程序完全没问题。
后续开发过程中,对myfun做了点改动,
void myfunL(long long i) { }
在自己的程序中调用编译好的库函数时,如果库函数会输出一些提示信息(比如初始化信息、版本信息或者警告信息)而你又不喜欢这些信息,并且你希望保留另外一些函数的标准输出,可以在编程调用时这样做:
通常C语言中实现可变参数函数的方法,要利用<stdarg.h>的库函数,比如
http://c-faq-chn.sourceforge.net/ccfaq/node261.html
看上去比较繁琐。
今天忽然想到可以借助结构体实现这样的功能。首先根据所有可能用到的参数定义一个结构体,比如
struct par_all { int var_i; int var_j; float var_x; float var_y; char *var_c; char *var_d; ... } myparam;
然后定义函数
The following error was reported when I was trying to install the k-correction and photo-z package from http://cosmo.nyu.edu/~mb144/kcorrect/
on a sgi altix 64-bit server with gnu-linux system:
/usr/bin/ld: /opt/kcorrect/bin/k_test_filter: hidden symbol `__modsi3' in /usr/lib/gcc-lib/ia64-redhat-linux/3.2.3/libgcc.a(__modsi3.oS) is referenced by DSO
collect2: ld returned 1 exit status
make[1]: *** [/opt/kcorrect/bin/k_test_filter] Error 1
while it passes without problem on my local ubuntu 8.10 system.
http://c-faq-chn.sourceforge.net/
非常实用的C语言编程参考手册,极力推荐。
最新评论
4 周 4 天 前
4 周 6 天 前
8 周 6 天 前
13 周 6 天 前
24 周 1 天 前
43 周 2 天 前
1 年 3 周 前
1 年 3 周 前
1 年 11 周 前
1 年 12 周 前