static variableS with same name

1. 多个c文件,每个文件都包含static int a;

2. 一个c文件中,有一个全局static int a;,在某个函数中,也有一个相同定义static int a;

这两种情况都是合法的,另外这些变量a都是存放在同一个data段,那么C怎么区分各个变量的呢?

Since there can be as many function-local statics with the same name as you like (provided they are all in different scopes), the compiler might have to change their names internally (incorporating the function's name or the line number or whatever), so that the linker can tell them apart.

checkout this stackoverflow for more example and details.

发布了34 篇原创文章 · 获赞 0 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/hfyinsdu/article/details/105162232