[英]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? 我们可以通过给静态在C中的2个不同文件中使用相同的函数名吗? Like static myfunc() in file1.c and static myfunc() in file2.c.
像file1.c中的静态myfunc()和file2.c中的静态myfunc()。 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. 声明为
static
全局名称具有内部链接 ,这意味着这样的名称对于翻译单元是私有的。 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. 更具体地, 在一个翻译单元内,名称的所有
static
声明指的是相同的对象或功能,但是在每个翻译单元中,这种声明指的是不同的对象或功能。 (By contrast, all names with external linkage refer to the same entity across the entire program.) (相比之下,所有具有外部链接的名称都指的是整个程序中的同一实体。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.