小编moh*_*qub的帖子

返回指向 C 中全局静态结构对象的指针

typedef struct
{
   int age;
   int number;
} person;

static person self;//global declaration 

person *Self(){
    return &self;
}
Run Code Online (Sandbox Code Playgroud)

我一直在尝试理解上面的类似代码,该代码在大型代码库中使用,任何帮助将不胜感激。

  1. 为什么我们需要像上面这样的Self()C 函数?
  2. 有什么好处?
  3. 有什么缺点吗?

c static struct

0
推荐指数
1
解决办法
274
查看次数

标签 统计

c ×1

static ×1

struct ×1