Using extern keyword to call functions

后端 未结 4 1343
借酒劲吻你
借酒劲吻你 2021-01-21 21:37

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

Can I extern the function1 to call it? Also, do I have to use extern in <

4条回答
  •  广开言路
    2021-01-21 22:11

    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;
    }
    

    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;
    }
    

提交回复
热议问题