| |||||
Technical Support Support Resources
Product Information | C251: INLINE MACRO FUNCTIONSQUESTIONI would like to create a function that can be written as a separate routine and appear in the code to be a separate function, but in compiling will be inserted directly in the code rather than called by a CALL instruction. Other C compilers often support macros or "inline" functions that accomplish this. Is there any way to do this with the Keil C251 Compiler? ANSWERYes. The following example program shows how you can use #defines in C to insert C code inline. Note that parameters (a and b) are passed to these macros.
#define func_part_1(a,b) a ^= b; b ^= a; a ^= b;
#define func_part_2(a,b) if (a) b = 0; if (b) a = 1;
void func (unsigned int a, unsigned int b)
{
func_part_1 (a,b);
func_part_2 (a,b);
}
Also note that the backslash character ('\') is required to continue the macro on the next line. Last Reviewed: Sunday, May 16, 2004 | ||||
| |||||