如何处理C之内重复功能的名称? [英] How to deal with duplicated function name within C?

查看:134
本文介绍了如何处理C之内重复功能的名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小项目中,我在两个不同的源文件中两个名为名称相同的功能,但同时我建设项目中,编译器。在filename.obj已经定义FUNC_NAME'失败

I have a little project in which I named two same name function in two different source file, but while I building the project, the compiler failed with 'func_name already defined in filename.obj'.

为什么我不能有两个不同的源文件中的两个同名的功能呢?我认为功能应该是本地的源文件只有当我们在头文件中声明它,它会成为全球性的。

Why could not I have two functions with the same name in two different source files? I thought the function should be local to the source file only if when we declared it in the header file will it become global.

和除了改变文件名,还有什么优雅的解决方案,以复制函数名C编程语言?

And except for changing the filename, are there any other elegant solution to duplicated function name in the C programming language?

推荐答案

在C,功能在默认情况下全球范围内。要限制其范围,使用静态关键字,使其私有到该模块。

In C, a function has global scope by default. To restrict its scope, use the static keyword to make it private to a the module.

头文件的作用仅仅是利用它的签名对其他模块一起公布的功能。

The role of the header file is just to publicize the function along with its signature to other modules.

所有的全局名称必须(有一些注意事项)是唯一的。这是有道理的,因为这名字是什么所使用的连接器,以一个函数调用连接到实现功能本身。

All global names must (with some caveats) be unique. This makes sense because that name is what is used by the linker to connect a function call to implementation of the function itself.

静态和地方范围的名称只需要在其范围内是唯一的。

Names with static and local scope need only be unique within their scope.

这篇关于如何处理C之内重复功能的名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆