程序整理后未声明的标识符? [英] Undeclared identifiers after program tidy-up?

查看:75
本文介绍了程序整理后未声明的标识符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开始将我的代码拆分为模块,位于编译器的同一个Project文件夹中。我已经尽力解决这个问题,现在我需要一位专家!


例如,在一个.C文件中,我有一个函数clsLCD()。这是在关联的.C文件中定义并声明为原型,并在我的definitions.h文件中声明为原型。但是,当我构建项目时,我在与另一个调用该函数的.C文件相关的表达式中获得了未声明的标识符''clsLCD''。


我被告知要使用extern重复定义,但是我必须在所有中重复所有定义其他模块,或者我可以使用单个defs.c。文件中包含这些外部定义吗?


有人可以查看这些文件并解释如何摆脱这些错误。


TIA


Nigel

I''ve started to split my code into modules, within the same Project folder in my compiler. I''ve done my best to sort this out, now I need an expert!

For example, in one of the .C files I have a function clsLCD(). This is defined and declared as a prototype in the associated .C file, plus declared as a prototype in my definitions.h file. However, when I build the project I get Undeclared identiifier ''clsLCD'' in expression relating to another .C file that calls the function.

I''ve been told to repeat the definitions using extern, but do I have to repeat all the definitions in all the other modules, or can I have a single "defs.c" file with these extern definitions in it?

Could someone have a look at these files and explain how to get rid of these errors.

TIA

Nigel

推荐答案

我问过几天的问题之前关于在不同的c文件中共享全局变量。
包括标题文件


这可以帮助你理解外部


问候,

johny
I have asked a question several days ago about sharing a global variable in different c files.
including header file.

This can help you to understand extern

regards,
johny


你好Johny,


我想我明白extern意味着什么,但我仍然对如何解决我的问题感到困惑。
Hi Johny,

I think I understand what extern means, but I''m still confused about how to resolve my problem.


您的extern声明不应该在任何C / CPP源文件中。应该在H头文件中。然后,您可以将该头文件#include到所有C / CPP文件中,从而确保所有源文件都看到相同的声明集。
You extern declarations should not be in any C/CPP source files. The should be in a H header file. You can then #include that header file into all your C/CPP file thus ensuring all the source files see the same set of declarations.


这篇关于程序整理后未声明的标识符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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