简体   繁体   中英

Can we use same function name in 2 different file in C by giving static?

Can we use same function name in 2 different file in C by giving static? Like static myfunc() in file1.c and static myfunc() in file2.c. Will linker understand the scope or it will throw the error?

static 告诉函数或数据元素只在编译单元的范围内是已知的所以你的问题的答案是肯定的,你将能够声明一个具有相同名称的静态函数, 甚至在两个不同的编译中使用相同的签名单位

是的,这是可以的,并且是static关键字的一个要点。

Global names declared static have internal linkage , which means that such a name is private to the translation unit. More specifically, within one translation unit, all static declarations of a name refer to the same object or function, but in each translation unit, such a declaration refers to a distinct object or function. (By contrast, all names with external linkage refer to the same entity across the entire program.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM