c++macros

Concat for predefined macros


I would like to make single string from __FILE__, __FUNCTION__, and __LINE__ predefined macros.

#define LOG_LINE __FILE__ " " __FUNCTION__ " " __LINE__

This probably will don't work because compiler concat don't work with integers which __LINE__ is.
#define LOG_LINE __FILE__ __FUNCTION__
also don't work, because:
error: expected ';' before '__FUNCTION__'

How to achieve that to have std::cout << LOG_LINE which will expand to e.g. main.cpp main 8?

Solution: #define LOG_LINE __FILE__ << " " << __FUNCTION__ does not satisfy me because sometimes I would like to use it as string (big macro with sstream also is not valid solution ;).


Solution

  • You may use the following:

    #define LOG_LINE (std::string(__FILE__ " ") +  __FUNCTION__ + " " + std::to_string(__LINE__))
    

    Live example