stringize the function name

Vlearns used Ask the Experts™

i came upon some code in c++ with the following syntax in a Folder class

a function declaration is the usual one but the next line is

static const char* FUNC_NAME = "Folder::update_folder()";  which is the name of the function..this is trying to convert the function name into some kind of string???? what purpose does it serve?

see below:

int   Folder::update_folder(bool noop = false)
      static const char* FUNC_NAME = "Folder::update_folder()";
....more code here......


Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
It would be useful to see the usage of FUNC_NAME. However, it is common to see this type of form to indicate in debug logging purposes what class and class member is logging the output.
> "convert the function name into some kind of string"
No, there is no conversion or stringizing taking place; just creating a string of the form:
In C or C++, if you chose to have the convention that the class name was embedded in the file as in <ClassName>.cpp, the macro __FILE__ does stringize the file name (and you could then remove the .cpp portion). __LINE__ would stringize the line number.
Top Expert 2009

C99 provides __func__ too. But today, it's still highly compiler dependent. Boost has a nice alternative though :

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial