note: I am using g++ version 4.3.4
So I was learning about assert statements and came across a homebrew assert macro that uses that variables __LINE__ and __FILE__ which (cleverly) give the line number and the file name from where they were called — in this case, from where the assertation failed. These are epic pieces of information to have!
I was able to infer that the variable __FUNCTION__ will give you the function name that you are inside of… amazing!! However, when assert.h is at work, you also get the arguments to the function (i.e. function: int main(int, char**) and all I can do currently is get the function name…
Generally speaking, where can I learn more about these wonderful hidden variables and get a complete list of all of them?
p.s. I guess I understand now why you aren’t supposed to use variable names starting with __
As far as getting the function arguments, you can try using
__PRETTY_FUNCTION__instead of__FUNCTION__. More information is available here: http://gcc.gnu.org/onlinedocs/gcc/Function-Names.htmlAs far as a list of pre-defined macros, you can find a lot of them if you hunt around in here: http://gcc.gnu.org/onlinedocs/cpp/Predefined-Macros.html#Predefined-Macros
I cannot say with certainty that the list referenced above is complete. The reason I say this is that
__PRETTY_FUNCTION__cannot be found under the list of predefined macros… why this is, I cannot say.