Understanding the Differences: PRETTY_FUNCTION__, __FUNCTION__, and __func
In programming, accessing information about the current function can be useful for debugging, logging, and other purposes. Three commonly used identifiers in C and C serve this function: __PRETTY_FUNCTION__, __FUNCTION__, and __func__. Each one holds its own unique characteristics worth understanding.
__func__: A Standard Identifier from C99
Defined in C99, func is an implicitly declared identifier that expands to a character array containing the name of the function in which it is used. As a declared identifier, func behaves differently than a preprocessor macro.
__FUNCTION__: A Pre-Standard Extension
Widely supported by C compilers like gcc and Visual C , FUNCTION is not strictly a part of the C standard. It typically behaves similarly to __func__, but some inconsistencies between compilers may exist.
__PRETTY_FUNCTION__: A GCC Extension
PRETTY_FUNCTION is a gcc-specific extension that is comparable to __FUNCTION__. However, for C functions, it returns the "pretty" name, which includes the function's signature.
Choosing the Right Identifier
Selecting which identifier to use primarily depends on support and functionality requirements:
It's also important to consult specific compiler documentation for nonstandard extensions like FUNCTION and __PRETTY_FUNCTION__. For example, Visual C offers similar extensions like __FUNCSIG__.
The above is the detailed content of What's the Difference Between `__PRETTY_FUNCTION__`, `__FUNCTION__`, and `__func__`?. For more information, please follow other related articles on the PHP Chinese website!