Whole document tree
    

Whole document tree

Using the GNU Compiler Collection: Other Builtins
[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.40 Other built-in functions provided by GNU CC

GNU CC provides a large number of built-in functions other than the ones mentioned above. Some of these are for internal use in the processing of exceptions or variable-length argument lists and will not be documented here because they may change from time to time; we do not recommend general use of these functions.

The remaining functions are provided for optimization purposes.

GNU CC includes builtin versions of many of the functions in the standard C library. These will always be treated as having the same meaning as the C library function even if you specify the `-fno-builtin' (see section 2.4 Options Controlling C Dialect) option. These functions correspond to the C library functions alloca, ffs, abs, fabsf, fabs, fabsl, labs, memcpy, memcmp, strcmp, strcpy, strlen, sqrtf, sqrt, sqrtl, sinf, sin, sinl, cosf, cos, and cosl.

You can use the builtin function __builtin_constant_p to determine if a value is known to be constant at compile-time and hence that GNU CC can perform constant-folding on expressions involving that value. The argument of the function is the value to test. The function returns the integer 1 if the argument is known to be a compile-time constant and 0 if it is not known to be a compile-time constant. A return of 0 does not indicate that the value is not a constant, but merely that GNU CC cannot prove it is a constant with the specified value of the `-O' option.

You would typically use this function in an embedded application where memory was a critical resource. If you have some complex calculation, you may want it to be folded if it involves constants, but need to call a function if it does not. For example:

 
#define Scale_Value(X)  \
  (__builtin_constant_p (X) ? ((X) * SCALE + OFFSET) : Scale (X))

You may use this builtin function in either a macro or an inline function. However, if you use it in an inlined function and pass an argument of the function as the argument to the builtin, GNU CC will never return 1 when you call the inline function with a string constant or constructor expression (see section 4.19 Constructor Expressions) and will not return 1 when you pass a constant numeric value to the inline function unless you specify the `-O' option.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated by root on January, 30 2002 using texi2html