简体   繁体   English

我们可以通过给静态在C中的2个不同文件中使用相同的函数名吗?

[英]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.

相关问题 我们可以在 2 个不同的库文件中使用相同的 function,如果两个库都在同一个 DLL 文件中使用 - Can we use same function in 2 different library file , if both the library consumed in same DLL file 我们可以在 C 的不同函数中声明相同的局部静态变量吗? - can we declare the same local static variable in different functions in C? 我们可以在C中使用没有名称的函数吗? - Can we have a function without a name in C? 静态变量名称与C中允许的函数名称相同吗? - Is a static variable name, same as function name allowed in C? 我们可以从同一个函数返回指向新静态数组的指针吗? - Can we return pointer to new static array from the same function? 在不同文件中用相同名称定义静态内联函数可以吗? - Is it ok to define static inline function with same name in different files? 在不同的C模块中使用具有相同名称的静态函数是不好的做法吗? - Is it bad practice to have static functions with the same name in different C modules? 是否允许使用相同的 static void function 在 c 中使用多个线程? - Is it allowed to use the same static void function to use multiple threads in c? 是否可以在单个C文件中声明具有相同名称的多个静态变量? - Is it possible to declare multiple static variables with same name in a single C file? 可以声明两个具有相同名称的函数,返回类型但不同的参数 - Can c declare two function with the same name, return type but different parameters
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM