Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3314870
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:17:01+00:00 2026-05-17T22:17:01+00:00

I want to know how to find out if the preprocessor macro __PRETTY_FUNCTION__ can

  • 0

I want to know how to find out if the preprocessor macro __PRETTY_FUNCTION__ can be used with a given compiler (As it is supposed to be non-standard). How do I check this in a header file? What I want to do is something like:

#ifndef __PRETTY_FUNCTION__
   #define __PRETTY_FUNCTION__ __func__
#endif

But, I’m guessing what happens is the preprocessor defines the macro in place for each function so I wonder whether there’s any meaning to __PRETTY_FUNCTION__ (Unlike __FILE__ or __LINE__) outside a function. Is this true or can I just use the code above? If not, how do I check for it?

EDIT: I tried it. __PRETTY_FUNCTION__ is undefined outside a function (I didn’t check inside a class). So there has to be another way.

EDIT2: Actually a simple hack would be to do this :):

void Dummy()
{
    #ifndef __PRETTY_FUNCTION__
       #define __PRETTY_FUNCTION__ __func__
    #endif
}

The other method is to check for compiler as was suggested by others.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T22:17:01+00:00Added an answer on May 17, 2026 at 10:17 pm

    You probably have to know which compiler you’re using. For GCC (the GNU Compiler Collection), you’d probably test:

    #ifdef __GNUG__
    ...use __PRETTY_FUNCTION__
    #endif
    

    You might check the compiler version if you know which one introduced the feature and you are in any danger of having your code compiled with an older version.

    The GCC (4.4.1) manual says:

    In C, __PRETTY_FUNCTION__ is yet another name for __func__. However, in C++, __PRETTY_FUNCTION__ contains the type signature of the function as well as its bare name.
    For example, this program:

     extern "C" {
         extern int printf (char *, ...);
     }
     class a {
     public:
         void sub (int i)
         {
             printf ("__FUNCTION__ = %s\n", __FUNCTION__);
             printf ("__PRETTY_FUNCTION__ = %s\n", __PRETTY_FUNCTION__);
         }
     };
     int
     main (void)
     {
         a ax;
         ax.sub (0);
         return 0;
     }
    

    gives this output:

     __FUNCTION__ = sub
     __PRETTY_FUNCTION__ = void a::sub(int)
    

    These identifiers are not preprocessor macros. In GCC 3.3 and earlier, in C only, __FUNCTION__ and __PRETTY_FUNCTION__ were treated as string literals; they could be used
    to initialize char arrays, and they could be concatenated with other string literals. GCC
    3.4 and later treat them as variables, like __func__. In C++, __FUNCTION__ and __PRETTY_
    FUNCTION__
    have always been variables.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to know which tool can be used to measure the cyclomatic complexity
I want to know how stl hash_map is implemented. How do I find out
Greetings everyone! I want to know if its possible to find out if a
I know a role name and want to find all users in this role.
I know the name of the table I want to find. I'm using Microsoft
Want to know what the stackoverflow community feels about the various free and non-free
I want to know if i can create a custom google maps application,on which
I want to find out via reflection if a field is an instance of
I want to find out how many periods (custom) are there between two dates.
I want to know the best way to compare two objects and to find

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.