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.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章