C++C++11C++14C++17Learn C++

Learn To Use Predefined Identifier __func__ In C++

Learn To Use Predefined Identifier func In C++

Modern C++ has a lot of features that can be used in professional programmingC++11 standard improved the previous C99 standard feature __func__ which is a predefined identifier for functions or methods. The predefined identifier __func__ returns as a string that contains the name of the enclosing function or method. In this post, we explain how we can use predefined identifier __func__ in modern C++.

What is the predefined identifier __func__ in C++?

The predefined identifier __func__ returns as a string that contains the name of the enclosing function or method. In other words, it returns the string that contains the name of the function that is called from. This basic feature from C99 requires some modification to integrate with C++, and with C++11 it is improved to support strings in addition to char arrays. This a kind of constant string and the syntax is as below,

and here is a simple example to display function name:

and when we run this function, it will print out its name as below.

Is there a full example about the predefined identifier __func__ in C++?

Here is a full example about the predefined identifier __func__ in modern C++. In this example, we used __func__ in both function and method,

here is the output,

This feature is generally used to capture function names as string literals and to assist diagnostic libraries. Sometimes we want to know the name of the function that is called, you can decide some sub operations by the function that is called.

For more information on this feature, see Adoption of C99’s __func__  and  __func__ predefined identifier Proposal document.

Learn To Use Predefined Identifier func In C++ C++ Builder logo

C++ Builder is the easiest and fastest C and C++ IDE for building simple or professional applications on the Windows, MacOS, iOS & Android operating systems. It is also easy for beginners to learn with its wide range of samples, tutorials, help files, and LSP support for code. RAD Studio’s C++ Builder version comes with the award-winning VCL framework for high-performance native Windows apps and the powerful FireMonkey (FMX) framework for cross-platform UIs.

There is a free C++ Builder Community Edition for students, beginners, and startups; it can be downloaded from here. For professional developers, there are Professional, Architect, or Enterprise version.

Oh hi there 👋
It’s nice to meet you.

Sign up to receive awesome C++ content in your inbox, every day.

We don’t spam! Read our privacy policy for more info.

About author

Dr. Yilmaz Yoru has 35+ years of coding with more than 30+ programming languages, mostly C++ on Windows, Android, Mac-OS, iOS, Linux, and some other operating systems. He graduated and received his MSc and PhD degrees from the Department of Mechanical Engineering of Eskisehir Osmangazi University. He is the founder and CEO of ESENJA LLC Company. His interests are Programming, Thermodynamics, Fluid Mechanics, Artificial Intelligence, 2D & 3D Designs, and high-end innovations.
Related posts
C++C++11C++14Learn C++Syntax

How To Convert u32string To A wstring In C++

C++C++11C++14C++17C++20Introduction to C++Learn C++

How To Learn The Move Constructors In Modern C++?

C++C++17Code SnippetLearn C++

How To Convert Char Array String To Unicode String Correctly In C++?

Artificial Intelligence TechC++Language FeatureLearn C++

How To Develop A Simple Hopfield Network In C++