print the its own function name

This is a discussion on print the its own function name within the C++ Programming forums, part of the General Programming Boards category; Dear there, is there a way to print the function's name inside itself? I know the trick to print a ...

  1. #1
    Registered User
    Join Date
    Dec 2008
    Posts
    48

    print the its own function name

    Dear there, is there a way to print the function's name inside itself? I know the trick to print a variable name in macro using #:
    #define P(x) cout << #x << ": " << x << endl;
    I am wondering whether there is a similar way to do it for functions.

  2. #2
    The larch
    Join Date
    May 2006
    Posts
    3,573
    GCC has the __FUNCTION__ and __PRETTY_FUNCTION__ macros. Other compilers probably have same or similar macros.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  3. #3

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ compilation issues
    By Rupan in forum C++ Programming
    Replies: 1
    Last Post: 08-22-2005, 06:45 AM
  2. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 11:03 AM
  3. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 07:18 AM
  4. Creating a student grade book-how?
    By Hopelessly confused in forum C Programming
    Replies: 5
    Last Post: 10-03-2002, 09:43 PM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 02:27 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21