26 Built-in Functions

Built-in functions are coded in C source files syntactically like function calls, but are typically compiled into short assembly code sequences that directly implement the required function without calling a C function or library routine. These functions give the C programmer access to assembler operators or machine instructions that are currently only accessible using inline assembly, but are sufficiently useful that they are applicable to a broad range of applications.

There are no header files associated with built-in functions, as they are not true C functions. The -f[no]builtin option controls whether the built-in functions provided by the compiler are recognized in projects. The built-in function names all begin with the _ _builtin_ prefix, and hence do not belong to the compiler’s namespace and not conflict with function or variable names in the programmer’s namespace.

There are a number of reasons why providing built-in functions is preferable to requiring programmers to use inline assembly. They include the following:

  1. Providing built-in functions for specific purposes simplifies coding.
  2. Certain optimizations are disabled when inline assembly is used. This is not the case for built-in functions.
  3. For machine instructions that use dedicated registers, coding inline assembly while avoiding register allocation errors can require considerable care. The built-in functions make this process simpler as you do not need to be concerned with the particular register requirements for each individual machine instruction.