Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible in C/C++ to put the name of a function into the code at compile time?

Tags:

c++

c

function

I will have hundreds of functions such as this

void OrganOut() 
{       
    Title("OrganOut");

Where the first line puts the title of the function up on the LCD display (it's an embedded music system as you can probably guess by the name). As the function name is obviously known at compile time, is there any way to automate placing the name in Title to avoid entering the name twice ?

like image 687
Mike Bryant Avatar asked Mar 14 '19 13:03

Mike Bryant


People also ask

When function is selected for execution at the compilation time is called as?

In computing, compile-time function execution (or compile time function evaluation, or general constant expressions) is the ability of a compiler, that would normally compile a function to machine code and execute it at run time, to execute the function at compile time.

What is the use of time in C++?

The time () function is defined in time.h (ctime in C++) header file. This function returns the time since 00:00:00 UTC, January 1, 1970 (Unix timestamp) in seconds. If second is not a null pointer, the returned value is also stored in the object pointed to by second.

How to call a function in C programming?

In such case, you should declare the function at the top of the file calling the function. While creating a C function, you give a definition of what the function has to do. To use a function, you will have to call that function to perform the defined task. When a program calls a function, the program control is transferred to the called function.

How do I make C++ code compile as C code?

In Configuration Properties > C/C++ > Precompiled headers, set Precompiled Headers to: "Not using Precompiled Headers" In the same C/C++ branch, go to Advanced, change Compile As to: "Compile as C code (/TC)"

How many functions can be defined in a C program?

Every C program has at least one function, which is main (), and all the most trivial programs can define additional functions. You can divide up your code into separate functions.


1 Answers

You are looking for __func__.

void OrganOut() 
{       
    Title(__func__);
}

This feature is available from the C99 and C++11 standards respectively.

like image 146
Lundin Avatar answered Sep 17 '22 15:09

Lundin