Why is my symbolic constant not global? K&R problem related

This is a discussion on Why is my symbolic constant not global? K&R problem related within the C Programming forums, part of the General Programming Boards category; Hi,
I'm having a problem with one of the sample programs in the K&R book (second edition). Its the calculator ...

Why is my symbolic constant not global? K&R problem related

I'm having a problem with one of the sample programs in the K&R book (second edition). Its the calculator program in chapter 4.

A good portion of questions in that chapter revolve around this program (whose source code they have provided). So i've tried compiling it, and it won't compile!

The problem appears to be that the symbolic constant "NUMBER" in polishCalc.c isn't being recognized in getop.c . Its declared outside all functions in polishCalc.c, so I don't understand why it isn't being recognized in getop.c. Interestingly enough, global variables seem to be recognized between the two source files... it is only with global symbolic constants that I'm having this problem.
It fails to work with and without "extern" before NUMBER.

Since the use of the constant is so trivial, it would take about .02 seconds to get the program to compile and work correctly. But why it isn't working is bothering me so much that I had to seek help.

#define statements don't declare an actual variable for you to reference elsewhere via an extern statement. What happens with NUMBER (within polishCalc.c only) is that instances of the token/symbol NUMBER are replaced with its #define'd value of 0 as the code is compiled... it, the symbol NUMBER, is simply understood by the compiler to mean 0 because of the #define when it encounters the symbol.

This tells your linker that there exists an integer in another source file called NUMBER. As I stated, the #define does not create an actual integer variable called NUMBER. Since the variable does not exist, the linker should complain that it cannot find the variable.

rags_to_riches suggestion, to put the #define in a header and include that header in the necessary source files, makes the symbol NUMBER visible to any source file which includes the header but it still is not an actual instance of an integer variable (you wouldn't need the extern line at all).

"Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
-Christopher Hitchens