我能否在C中创建具有未解决的依赖关系的函数?

问题描述 投票:-2回答:3

什么是最短最简单的方法来解决以下依赖性问题。鉴于此,我必须将xx保留在单独的文件中。

file1.h

    static inline void xx(){
      yy();//yy is not defined in this file but defined in file2.c;
    }

file2.c

  #include "file1.h"
  void yy(){
     printf("Hello");
   }

    void main(){
      xx();
    }

未定义文件1中的编译器错误。

c inline extern
3个回答
1
投票

需要声明,但没有定义:

// file1.h

static inline void xx() {
    void yy(); // Just a declaration

    yy(); 
}

1
投票

预声明yy


1
投票

只需在使用函数之前声明就可以解决问题。

© www.soinside.com 2019 - 2024. All rights reserved.