Keil Logo



I 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?


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

Did this article provide the answer you needed?
Not Sure
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.