ARM Technical Support Knowledge Articles

SCOPE OF #DEFINE

Applies to: C Programming Language

Answer


Information in this article applies to:


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.

Article last edited on: 2004-04-24 14:46:23

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential