0

How to have a macro kind of thing in C++ for having a function name and line number in the debugging info. For example

std::cout << "F:" << __FUNCTION__ << ":L:" << __LINE__ << ":"
          << "Doing specific operation" << std::endl;

In the above statement, I would like to have some shorter notation for

"F:" << __FUNCTION__ << ":L:" << __LINE__ << ":"

in order to replace the same with an alias. I should be able to use the alias through out the function for logging purposes.

Venkata Pavan
  • 105
  • 1
  • 1
  • 4
  • 2
    What have you tried? How did your attempt work or not worked? Please review [how to ask good questions](http://stackoverflow.com/help/how-to-ask), as well as [this question checklist](https://codeblog.jonskeet.uk/2012/11/24/stack-overflow-question-checklist/). And or course please try to create a [mcve] to show us. – Some programmer dude Nov 19 '18 at 07:31
  • Why just no define another macro? `#define DEBUG_INFO "F:" << __FUNCTION__ << ":L:" << __LINE__ << ":"` ? Note that `__FUNCTION__ ` and `__LINE__ ` will be expanded in place, after the containing macros are expanded, so they will still contain the correct information, despite being defined inside some header file – LoPiTaL Nov 19 '18 at 07:33
  • You might look at [std::experimental::source_location](https://en.cppreference.com/w/cpp/experimental/source_location). – Jarod42 Nov 19 '18 at 10:45

0 Answers0