使用extern关键字调用函数 [英] Using extern keyword to call functions

查看:274
本文介绍了使用extern关键字调用函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从其他调用c.test.c中定义的函数.

I want to call functions defined in test.c from other.c.

我可以extern function1调用它吗?另外,我是否必须在function2function3中使用extern,它们被function1调用?

Can I extern the function1 to call it? Also, do I have to use extern in function2 and function3, which are being called by function1?

other.c

extern function1();
function1();

test.c

void function1()
{
    function2();
    function3();
}

void function2()
{

}

void function3()
{

}

推荐答案

实际上,默认情况下,每个函数都是extern :)-除非您声明它们不是:).如果您在第一次调用之前就拥有了原型,就足够了;

Actually every function by default is extern :) - unless you declare them to be not :). It is enough if you have the prototype before the first call;

int xxx(int, int, float, double);  // prototype


int main(void)
{
  int x,y;
  float z;
  double v;

  xxx(x,y,z,v);

  return 0;
}


该功能可以位于另一个.c文件中.您需要将目标文件包括在链接中.


Function can be in the another .c file. You need to include the object file to the linking.

int xxx(int a, int b, float c, double d)
{
  int result;
  /* do something */

  return result;
}

这篇关于使用extern关键字调用函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆