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

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

Children