C program to print the function names defined in the source code

Here, we are going to learn how to print the function names defined in the source code using C program?
By Nidhi Last updated : March 10, 2024

Problem Solution

In this program, we will use __FUNCTION__ macro to print the function name, also we will print all function names defined in the source code.

__FUNCTION__ Macro

This macro is used to return the current function name. It is useful for debugging i.e., to generate the logs.

Program

The source code to print the function names defined in the source code is given below. The given program is compiled and executed using GCC compile on UBUNTU 18.04 OS successfully.

// C program to print the function names
// defined in source code

#include <stdio.h>

void func1()
{
    printf("%s\n", __FUNCTION__);
}

void func2()
{
    printf("%s\n", __FUNCTION__);
}

void func3()
{
    printf("%s\n", __FUNCTION__);
}

int main()
{
    printf("Function are: \n");

    func1();
    func2();
    func3();

    printf("%s\n", __FUNCTION__);

    return 0;
}

Output

Function are: 
func1
func2
func3
main

Explanation

In the main() function, we called func1(), func2(), func3() function and print the function names using __FUNCTION__ macro on the console screen.

C Preprocessors Programs »

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.