我有一个变量,我想在程序运行之前在运行时进行初始化。初始化后,我不希望变量的值改变。有没有任何C语言构造去做这件事?需要在运行时初始化的预期常量变量
让我的主C程序被包含在一个文件prog.c中
//Contents of Prog.c
//...includes.. and variable initialization
int main(..)
{
//Initialize variables here
//.. Huge program after this where I don't want these constants to change
}
如果变量需要从访问:
然而,如果该值在编译时知道的,您可以在运行时将它设定其他功能在其他文件? –
然后,你必须传递一个指针。 – Jite
'* g_pVal'很容易'extern'ed,并且可以在任何链接的文件中使用。它是**全球**。 – abelenky