We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
If one macro is defined for "assignment": Ex. #define equal(a,b) {a=b; }
And write: equal(A,1); equal(A,2); equal(A,3);
where A is pointer to XDATA space(mapped to H/W)
Keil C will "optimize" them and final result is A=3 ? or Keil C won't do this and expand them one by one ?
Thanks in advance...
Thanks for all your opinions first ! Maybe i used unsuitable example...Below is the true story and I want to explain why.
@1 I got one code base and found the following way is used to access h/w registers: #define regA *((unsigned char xdata *) 0xa1) ... regA = 0xFF; ... while(regA);
@2 I try to add code segments: regA = 0x01; regA = 0x02; regA=0x03; and I found each statement is executed and no loss...
@3 "volatile" is not used above and my entire code did not use "volatile" , but h/w access works well. Besides, XBYTE/XWORD and _at_ are NOT used... (that is, the 3 ways listed in doc: http://www.keil.com/support/docs/1455.htm are NOT used)
I can not explain the phenomenon and the only thing I can suspect is: #define creates a macro and maybe after expansion these codes are NOT optimized...
"I can not explain the phenomenon"
I explained it to you in your other thread on exactly the same subject:
http://www.keil.com/forum/docs/thread13388.asp
That's the trouble with creating duplicate threads on the same subject!
Thanks for your opinion...Initially I thought these 2 were different and thus posted 2 threads.
Please help to remove one of them if available...
Thanks anyway !
Thanks for your opinion
It is not an "opinion" =:0
They did not respond with opinions, but with facts.
Another thing - a #define named equal(a,b) should really represent a comparison - (is a equal to b?).
If you want your define to assign values, you should call it assign(a,b). Now, this was an opinion - never use confusing names for variables, defines, functions, ...
But as already mentioned, the preprocessor is really a preprocessor (even if implemented inside the compiler) doing text-based search/replace in your source code before the compiler starts to decide what the code looks like and starts with optimizations/code generation.
Thanks for all the facts you provided ^o^