Selecting the Right Identifier for Function Name Acquisition
C and C offer several identifiers for retrieving the name of the active function during runtime: __PRETTY_FUNCTION__, __FUNCTION__, and __func__. This guide explores the differences between these identifiers and provides guidance on their usage.
__func__:
"__func__" is a C99-introduced identifier that represents a character array containing the function's name. It is implicitly defined within each function. In C , func was introduced in C 11, offering an implementation-defined string.
__FUNCTION__:
"__FUNCTION__" is a pre-standard extension supported by compilers like gcc and Visual C . However, it is recommended to use func where supported and FUNCTION only when func is unavailable.
__PRETTY_FUNCTION__:
"__PRETTY_FUNCTION__" is a gcc-specific extension that resembles __FUNCTION__. For C functions, it displays the "pretty" name, including the signature. Visual C has a similar extension, __FUNCSIG__.
Deciding Which Identifier to Use:
The choice depends on compiler support and the desired function name format:
Documentation:
The above is the detailed content of Which C/C Identifier Should I Use to Get a Function's Name at Runtime?. For more information, please follow other related articles on the PHP Chinese website!