boost implements a macro BOOST_CURRENT_FUNCTION in its current_function.hpp , the macro is to provide the full name of the function, for exception throw, logging etc.
What is interesting is that the macro is implemented inside a function.
What's the special reason of doing so?
....
namespace boost
{
    namespace detail
    {
        inline void current_function_helper()
        {
            #if defined( BOOST_DISABLE_CURRENT_FUNCTION )
                # define BOOST_CURRENT_FUNCTION "(unknown)"
            #elif ...
            #elif defined(__FUNCSIG__)
                # define BOOST_CURRENT_FUNCTION __FUNCSIG__
            #elif ....
            #else
                # define BOOST_CURRENT_FUNCTION "(unknown)"
            #endif
        }
    } // namespace detail
} // namespace boost
....
                Upon looking at the full implementation one sees that it makes use of several compiler specific "function signature" macros. Those macros are of course only valid inside a function.
The test #elif defined(__FUNCSIG__) is going to fail at file scope. And so must appear inside a function. Here the helper is introduced to supply a function scope for this check.
The documentation on MSDN confirms this:
- __FUNCSIG__ Defined as a string literal that contains the signature of the enclosing function. The macro is defined only within a function.
 
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With