I don’t know much about RTTI, but I believe that thanks to that you can retrieve the name of variables at run-time. Is it possible to retrieve the name of the function the thread is currently running ?
            Asked
            
        
        
            Active
            
        
            Viewed 765 times
        
    4
            
            
        - 
                    1No, RTTI doesn't return the **name** of variables, it allows you to determine their **type**. – Cody Gray - on strike Jan 07 '12 at 13:06
- 
                    1possible duplicate of [How can one grab a stack trace in C?](http://stackoverflow.com/questions/105659/how-can-one-grab-a-stack-trace-in-c) – Šimon Tóth Jan 07 '12 at 13:07
- 
                    Alright, I thought `typeid(var).name` was doing that but apparently it returns the name of the type of the variable. – qdii Jan 07 '12 at 13:08
- 
                    Why would you even care? – fredoverflow Jan 07 '12 at 13:08
- 
                    @FredOverflow: Debug information. – Xeo Jan 07 '12 at 13:10
- 
                    It could be debug information. In my case I want to make wrapper functions: from a shared object A.so, I want a function foo to call the same function foo on another shared object B.so I would have opened. – qdii Jan 07 '12 at 13:15
- 
                    @victor the result of `typeid(var).name` is implementation-defined. – Jan 09 '12 at 12:59
4 Answers
12
            C++11 standardized __func__ for the current function.
Various compilers support variations of __FUNCTION__, __PRETTY_FUNCTION__, and others.
 
    
    
        Xeo
        
- 129,499
- 52
- 291
- 397
2
            
            
        - 
                    Yes, but it is more GNU libc (or Linux) related than C++ or g++ specific. – Basile Starynkevitch Jan 07 '12 at 13:09
0
            
            
        No.
C++'s run-time type identification allows you to figure out the type of an object, but not the name of the method you're currently in.
 
    
    
        unwind
        
- 391,730
- 64
- 469
- 606
0
            
            
        No, it is not possible. C++ does not support reflection (neither static nor dynamic) (like e.g. C#). You would need some preprocessor magic to emulate that.
Apart from that, there is not necessarily a notion of a function/method name during run-time (this only available as debugging information if you compiled your sources with the corresponding flags).
 
    
    
        Andre
        
- 1,577
- 1
- 13
- 25
 
    