question on #define
can we do a #define at any point in the code?
say i perform some task, and get a result xyz. can i do a '#define RESULT xyx" at some point in the code? thanks. |
A define is expanded by the C pre-processor. What it does is that it replaces, textually, the first argument of the define with the second before passing the code on to the compiler.
Because of that, your question doesn't make sense! If the "answer" is not known at compile time, then (obviously) the pre-processor can't make the replacing. Regards Martin |
right! thanks! :)
|
#define will expand macros which can do things:
Code:
#define zout(z) memset(&z,0x00,sizeof(z)) Code:
// this function does a complex square calc |
Now I must raise a finger of warning:tisk:about the use of pre-processor macros.
Look at this seemingly innocent macro: Code:
#define MAX(x, y) ((x)>(y)?(x): (y)) Code:
MAX(++j, ++k); Code:
++j > ++k ? ++j : ++k; Regards Martin |
right. thanks. :)
|
But is not available for a lot of plain C implementations.
|
u mean, inline isnt ?
|
All times are GMT -5. The time now is 11:38 AM. |