THIS = 2 ;
THAT = 2 ;
int THAT;
You still don't get what is going on. Reread my original answer and focus on what job is performed by the "C Compiler Preprocessor" and what job is performed byt eh the "C Compiler Pass #1". I'll give you a hint. Pass #1 performs lexical analysis and builds a symbol table of identifiers.But if I change what THAT is later in the program, will the define recognise this? because the #define will be executed before the main program.
So, if I were to get THAT value through a keypad from a User...or would it be equal to the initial definition ofC:int THAT;
Yes. But your example has it backward: THIS is being defined as the same as THAT.Can you define a variable as another variable?
#define THIS THAT
THIS_THING=1;
THIS=2;
THAT_THING=1;
THAT=2;
No it won't. The preprocessor only replaces tokens that are equal to THIS with THAT. THIS_THING is a single token. The preprocessor also won't change occurrences of THIS that appear in string literals or in comments.Not to confuse matters further, the pre processor will change ALL occurrences of THIS, even when it appears in different variables...Becomes...Code:#define THIS THAT THIS_THING=1; THIS=2;
Code:THAT_THING=1; THAT=2;
WBahn beat me to it, but this is not correct. It's not a find/replace, the preprocessor tokenizes your source code and operates on tokens, not on text. One (very minor) clarification since WBahn mentioned comments: the preprocessor actually deletes all comments entirely, which makes sense since the compiler doesn't care about them.Not to confuse matters further, the pre processor will change ALL occurrences of THIS, even when it appears in different variables...Becomes...Code:#define THIS THAT; THIS_THING=1; THIS=2;
Code:THAT_THING=1; THAT=2;
#define Threshold USER_CONFIG
later once executed....
if (USER_ENTERED == 5) USER_CONFIG = 10;
Yes, if later in your code (after the assignment) you did something like printf("%i", Threshold), the preprocessor would change it to printf("%i", USER_CONFIG). It would do the same thing before the assignment, too (or if the assignment is skipped completely because the user entered something other than 5) but then you'd be trying to use an unassigned variable.Yes, I get that. I just have a unusual situation...
I am defining something that does not get assigned a variable until the program is executed and the User inputs (via command terminal) the value.
A quick example of the problem..
Therefore, will USER_CONFIG = 10 if they User enters 5 into the command terminal because the define has already been assigned.C:#define Threshold USER_CONFIG later once executed.... if (USER_ENTERED == 5) USER_CONFIG = 10;