C语言如何引用别的文件中的static函数 您所在的位置:网站首页 调用cpp定义函数 C语言如何引用别的文件中的static函数

C语言如何引用别的文件中的static函数

2024-07-10 03:08| 来源: 网络整理| 查看: 265

文章目录 C如何引用别的文件中的static函数如果是static函数呢?缺点是我必须在haha中使用my_static,有时候你可能不想立即使用my_static试验一下这样就可以在主函数中随便啥时候调用my_static了结论:你还得在static所在的文件里面搞点小动作才可以实现在别的文件里调用它。哎,苦哦!

C如何引用别的文件中的static函数 (1.cpp) #include #include "2.h" void main() { my(); } (2.cpp) #include "2.h" #include void my() { printf("我是外边的的函数,我被调用了\n"); } 2.h头文件 void my();

上面的非常好,没问题。

如果是static函数呢? (1.cpp) #include #include "2.h" void main() { my_static(); } (2.cpp) #include "2.h" #include static void my_static() { printf("我是外边的的函数,我被调用了\n"); } 2.h头文件 static void my_static();

在这里插入图片描述 出错了。 怎么办呢????

(1.cpp) #include #include "2.h" void main() { haha(); } (2.cpp) #include "2.h" #include static void my_static() { printf("我是外边的static的函数,我被调用了\n"); } void haha() { my_static(); }; 2.h头文件 static void my_static(); void haha();

很勉强??????

缺点是我必须在haha中使用my_static,有时候你可能不想立即使用my_static

============================================================================================================================================================================================================================================================================================================================================================================ nodeNestloop.c文件中定义了

static TupleTableSlot * ExecNestLoop(PlanState *pstate)

但是在

NestLoopState * ExecInitNestLoop(NestLoop *node, EState *estate, int eflags)

中选用了

NestLoopState *nlstate; /* check for unsupported flags */ Assert(!(eflags & (EXEC_FLAG_BACKWARD | EXEC_FLAG_MARK))); NL1_printf("ExecInitNestLoop: %s\n", "initializing node"); /* * create state structure */ nlstate = makeNode(NestLoopState); nlstate->js.ps.plan = (Plan *) node; nlstate->js.ps.state = estate; nlstate->js.ps.ExecProcNode = ExecNestLoop;

这样就似乎可以在外部调用了这个文件。 / / / / /

试验一下 (1.cpp) #include #include "2.h" void main() { struct stru stru1; use_my_static(&stru1); stru1.f(); } (2.cpp) #include "2.h" #include static void my_static() { printf("我是外边的static的函数,我被调用了\n"); } void use_my_static(struct stru *h) { h->f=my_static; };//作用要知道哦 2.h头文件 static void my_static(); struct stru{ void (*f)(); }; void use_my_static(struct stru *h); 这样就可以在主函数中随便啥时候调用my_static了 结论:你还得在static所在的文件里面搞点小动作才可以实现在别的文件里调用它。哎,苦哦!


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有