Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

Functions and macros

&pagelevel(4)&pagelevel

Most of the library functions are implemented as C functions, a few as macros. Some library functions are implemented both as a function and as a macro.

If a library function exists in both variants, the macro variant is generated for the call by default. A function call is generated if the name is enclosed within parentheses () or is undefined by means of the #undef statement. The selection of an appropriate variant in each case will depend on whether and which specific aspects (performance, program size, restrictions) are relevant to a particular program.

A function is a compiled program segment (module) which is available only once and is treated as an external subroutine at runtime. An organizational overhead is required for each function call during program execution, e.g. to manage the local, dynamic data of a function in the runtime stack, to save register contents, for return addresses, etc.

Some library functions can be generated inline under the control of the OPTIMIZATION compiler option. In such cases, the function code is inserted directly at the calling point, and the above-mentioned administrative activities are not required.

The following functions can be generated inline in the present version: strcpy(), strcmp(), strlen(), strcat(), memcpy(), memcmp(), memset(), abs(), fabs(), labs() (see also the manuals "C Compiler" [3 (Related publications)] and "C/C++ Compiler" [4 (Related publications)]).

A macro is a source program segment that is defined by means of a #define statement. During compilation, the macro name in the source program is replaced by the contents of the called macro whenever the macro is called.

Using macros can improve performance during program execution, since the runtime system is not required to perform administrative activities (see "function"); however, the size of the compiled program is increased due to the macro expansions.

The following should also be taken into account when using macros:

  • Macro names cannot be passed as arguments to any function that requires a pointer to a function as an argument.

  • The use of increment/decrement or compound assignment operators for macro arguments may produce undesirable side effects.

  • The header file containing the macro definition must always be included in the program.