gpt4 book ai didi

c - 如何访问 C 中的阴影全局变量?

转载 作者:太空狗 更新时间:2023-10-29 16:23:34 24 4
gpt4 key购买 nike

如何在 C 语言中访问隐藏的全局变量?在 C++ 中,我可以使用 :: 作为全局命名空间。

最佳答案

如果你的文件作用域变量不是静态的,那么你可以使用在嵌套作用域中使用 extern 的声明:

int c;

int main() {
{
int c = 0;
// now, c shadows ::c. just re-declare ::c in a
// nested scope:
{
extern int c;
c = 1;
}
// outputs 0
printf("%d\n", c);
}
// outputs 1
printf("%d\n", c);
return 0;
}

如果变量是用静态声明的,我看不到引用它的方法。

关于c - 如何访问 C 中的阴影全局变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/618769/

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