只有extern声明为const?

时间:2017-03-17 16:01:10

标签: c initialization extern

我可以将一个在初始时填充的变量声明为仅用于外部访问的const吗?

部首:

// foo.h:
extern const int foo;

来源:

// foo.c:
int foo;


void init_foo()
{
    static bool initialized = false;
    if (!initialized)
        foo = rand();
    initialized = true;
}

0 个答案:

没有答案
相关问题