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.
You can check the following links:
, . , , , .
, .
:
, #define USE_DEBUG #ifdef USE_DEBUG. , , .
#define USE_DEBUG
#ifdef USE_DEBUG
"" , #define SQR(x) ((x) * (x)), . , , i = 7; j = SQR(i++); , .
#define SQR(x) ((x) * (x))
i = 7; j = SQR(i++);
, #define OKAY 0, #define ERR_NOMEM 1 .. - - , , , .
#define OKAY 0
#define ERR_NOMEM 1
C " " IAR:
, , wiki C :
http://en.wikipedia.org/wiki/C_preprocessor
#define MACRO_FUNCTION(par1, par2) (par1 * par2) int product = MACRO_FUNCTION(4 ,5);
, MACRO_FUNCTION . , . . , .
Hello, As far as my knowledge goes the use of macro defs in embedded systems should
. : ( ), (, , bool), . , , , . , .