Keil™, An ARM® Company

Technical Support

C: SCOPE OF #DEFINE


Information in this article applies to:

  • All Keil Tools

QUESTION

I have a project that is composed of three source files. In one of my files, I #define a symbol. I want to access that symbol in the other source files but I receive an error indicating that the symbol is not defined.

ANSWER

#define is a preprocessor directive that allows you to specify a name and replacement text. As the preprocessor parses the source file, each occurrence of the name is replaces by its associated text.

The scope of #define is limited to the file in which it is defined. So, #defines which are created in one source file are NOT available in a different source file.

Typically, #defines which are shared between multiple files are stored in a header file (*.h) which is included in each source file that requires the #define.

Last Reviewed: Saturday, April 24, 2004


Did this article provide the answer you needed?
 
Yes
No
Not Sure