Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

__PRETTY_FUNCTION__ in Visual C++

While playing around with Visual C++ from Visual Studio 2017 (15.5.6 to be exact) I noticed that __PRETTY_FUNCTION__ from GCC seems to work! - to some degree at least…

It did show up along suggestions while typing: enter image description here

Also it had its value shown in tooltip as expected: enter image description here

And yet compiling the code using __PRETTY_FUNCTION__ results in an error:

error C2065: '__PRETTY_FUNCTION__': undeclared identifier

So, is there any way to make it work in Visual C++? Some include perhaps? Or some special compilation settings? (I think I'm using default ones.) Why would it work in shown examples, but not in actual use?!

Note, that I'm not looking for Visual C++ alternatives for __PRETTY_FUNCTION__. I know them already. I'm just surprised and curious about the behavior here.

like image 935
Adam Badura Avatar asked Feb 18 '18 23:02

Adam Badura


2 Answers

So, is there any way to make it work in Visual C++? Some include perhaps? Or some special compilation settings? (I think I'm using default ones.) Why would it work in shown examples, but not in actual use?!

No.

The Visual Studio uses the Edison Design Group C++ Front End for the InteliSense, as explained in the Visual C++ Team Blog's Rebuilding Intellisense and here, and not the Microsoft C++ compiler. This means that some of the features available to the Intellisense are not available in compile time.

EDG's C++ Front End documentation mentions that its supports some of the GCC pre-defines like __PRETTY_FUNCTION__ on page 71 - "1.13 Predefined Macros" together with Microsoft's __FUNCSIG__.

You can even see the version of the EDG by typing __EDG_VERSION__ and hovering over it.

like image 197
Mihayl Avatar answered Sep 24 '22 05:09

Mihayl


You can emulate it pretty well by putting this in some common header (for example, your precompiled header, if you're using that):

#if !defined(__PRETTY_FUNCTION__) && !defined(__GNUC__)
#define __PRETTY_FUNCTION__ __FUNCSIG__
#endif

It doesn't evaluate to exactly the same as PRETTY_FUNCTION, but it's a human-readable representation of the function name with argument types.

like image 44
Jon Watte Avatar answered Sep 23 '22 05:09

Jon Watte