Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) __func__

 

__func__ can be used to obtain the name of the current function.

 

__func__ is -as far is I know- optionally supplied by a compiler, for example by G++.

 

 

 

 

 

Example

 

The example below shows how to display a function name.

 

 

 

 

 

 

Technical facts

 

Application type(s)

Operating system(s) or programming environment(s)

IDE(s):

Project type:

C++ standard:

Compiler(s):

Libraries used:

 

 

 

 

 

Qt project file: Cpp__func__.pro

 

TEMPLATE = app
CONFIG += console
CONFIG -= qt
SOURCES += main.cpp

 

 

 

 

 

main.cpp

 

#include <iostream>

void ShowFunc()
{
  std::cout << __func__ << '\n';
}

int main()
{
  ShowFunc();

  std::cout << __func__ << '\n';
}

 

Screen output:

 

ShowFunc
main

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict

This page has been created by the tool CodeToHtml