I don't understand this error:
/*---------------------------------------------------------------------------- * This compiling OK, with Num1=22 *--------------------------------------------------------------------------*/ #define Num1 22
unsigned int TempW1; unsigned int TempW2;
int main (void) { TempW1 = Num1; TempW2 = TempW1 - Num1; while(1); }
Resul--> TempW2=0; it's OK
But
/*---------------------------------------------------------------------------- * This compiling ERROR, with Num1=21+1 *--------------------------------------------------------------------------*/ #define Num1 21+1
Resul--> TempW2=2; it's ERROR
What is happing????
"What is happing????"
1) You forgot to read the instructions on how to post source code. So the layout got totally garbled. How about being a bit more careful with the details. It really helps, if trying to write source code.
2) You did not spend too much time reading through all the good documentation about the meaning of #define - the glorified string-replace feature of the C language.
TempW1 = Num1; TempW2 = TempW1 - Num1;
Attempt 1:
#define Num1 22 TempW1 = 22; TempW2 = TempW1 - 22;
So TempW2 ended up with 22-22 => 0.
Attempt 2:
#define Num1 21+1 TempW1 = 21+1; TempW2 = TempW1 - 21+1;
So TempW2 ended up with 22 - 21 + 1 => 2.
This is covered a huge number of times in a huge number of publications about #define.
Have you ever seen examples of use of #define together with parentheses?
What you should have done:
#define Num1 (21+1) TempW1 = (21+1); TempW2 = TempW1 - (21+1);
Now your TempW2 gets the value 22 - (21+1) => 0.
Remember what I mentioned under item 1 above? It's all in the details. Start caring about them...