This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Macro will be "optimized" by Keil C ?

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...

Parents
  • 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...

Reply
  • 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...

Children