Suggestions for Learning Macros in C

I studied a programming course in programming languages ​​that covered C. However, not that I started working for a company in embedded systems, I see that C uses a lot of macros regularly.

Please share some links where I can learn more about macros.

I have K & R 2nd Ed, but I think their style is too brief. Something with more examples would be better for me.

+5
source share
6 answers

, .

, .

:

  • , #define USE_DEBUG #ifdef USE_DEBUG. , , .

  • "" , #define SQR(x) ((x) * (x)), . , , i = 7; j = SQR(i++); , .

  • , #define OKAY 0, #define ERR_NOMEM 1 .. - - , , , .

+5

C " " IAR:

+3

:

#define MACRO_FUNCTION(par1, par2) (par1 * par2)
int product = MACRO_FUNCTION(4 ,5);

, MACRO_FUNCTION . , . . , .

0
Hello,
As far as my knowledge goes the use of macro defs in embedded systems should 

. : ( ),   (, , bool), .   , , , .  , .

0

All Articles