[WnCC] Magic constant in gcc

20 views
Skip to first unread message

Kumar Ayush

unread,
Feb 20, 2018, 3:10:29 PM2/20/18
to wncc...@googlegroups.com
Dear Friends

I discovered this concept called magic constants in gcc. One of them, https://gcc.gnu.org/onlinedocs/gcc/Function-Names.html

allows you to print function details like this:

void func(args){
cout << __PRETTY_FUNCTION__;
}

would print func(args). It is not immediately obvious what is the use unless you delve into CPP coding where you extensively use templated functions.
--
Regards
Kumar Ayush
---

Kunal Tyagi

unread,
Feb 21, 2018, 2:37:46 AM2/21/18
to wncc...@googlegroups.com
There are similar but technically different macros such as

__LINE__, __FILE__: useful for debugging, logging
__FUNCTION__: useful for debugging c bindings
__STDC_HOSTED__: ensuring code runs with correct capabilities, eg: embedded only

These are preprocessor macros in gcc (and clang but official documentation is patchy). __PRETTY_FUNCTION__ is a special variable.

If you are using dynamic analysis, clang provides __has_feature(xyz) which really helps for debugging special issues.

PS: if you can't modify the source code, the cpp demangling is not that complicated. Esp if you use demangler.com

Cheers

--
--
The website for the club is http://wncc-iitb.org/
To post to this group, send email to wncc...@googlegroups.com
---
You received this message because you are subscribed to the Google Groups "Web and Coding Club IIT Bombay" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wncc_iitb+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Kumar Ayush

unread,
Feb 21, 2018, 4:10:03 AM2/21/18
to wncc...@googlegroups.com
A small remark; I don't believe they are pre-processor macros. They are variables. 

Please check the last line of the page I linked in my original email.
Reply all
Reply to author
Forward
0 new messages