Keil Logo

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
 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.