Function Name Macros in C and C
In C and C , several macros are available to access the name of the current function. These macros include __func__, __FUNCTION__, and __PRETTY_FUNCTION__.
func
Defined in C99 and adopted into C 11, func is an implicitly declared character array variable that holds the name of the enclosing function. It's a simple and lightweight option that provides the unadorned function name.
FUNCTION
FUNCTION is a pre-standard extension supported by certain compilers. Its behavior is similar to func__, but it's not part of the official language standards. It's preferable to use __func where available for portability reasons.
PRETTY_FUNCTION
PRETTY_FUNCTION is a GCC-specific extension that provides the "pretty" name of the function, including its signature. Unlike its predecessors, it's primarily useful in C to obtain the full function prototype with argument types.
Documentation
func is documented in the C99 standard, section 6.4.2.2/1. FUNCTION is not officially documented but is typically included in compiler-specific documentation. PRETTY_FUNCTION is documented on the GCC documentation page "Function Names as Strings."
When to Use Each Macro
The choice of macro depends on specific requirements:
The above is the detailed content of How to Choose Between `__func__`, `__FUNCTION__`, and `__PRETTY_FUNCTION__` for Accessing Function Names in C and C ?. For more information, please follow other related articles on the PHP Chinese website!