gpt4 book ai didi

我可以在 C 中创建具有 Unresolved 依赖关系的函数吗?

转载 作者:行者123 更新时间:2023-11-30 21:16:47 25 4
gpt4 key购买 nike

解决以下依赖问题的最短最简单方法是什么。鉴于,我必须将 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();
}

file1 yy 中的编译器错误未定义。

最佳答案

需要声明,但不需要定义:

// file1.h

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

yy();
}
// file2.c

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

int main() { // void main is not legal C
xx(); // Works fine.
}

关于我可以在 C 中创建具有 Unresolved 依赖关系的函数吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58572043/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com