typeid for functions in cpp

338 Views Asked by At

I was playing with typeid header-file in cpp. I passed a function name to the typeid function. When I did std::cout << ti.name() << std::endl I got FficE as output. I could figure out(kind of) everything except E. Can you guys explain how this works?

Here is the code:

#include <iostream>
#include <typeinfo>

float myFun(int num1, char num2){
    return 25.34;
}
int main(void){
    const std::type_info& ti2 = typeid(myFun); // O/P: FficE
    /*
     F: Function
     f: float (return type)
     i: integer (parameter 1)
     c: character (parameter 2)
     E: ?
     */

    std::cout << ti2.name() << std::endl;
    return 0;
}

I tried to read the official documentation but couldn't get much out of it. Also, I couldn't find a similar question asked here as well.

I'm using g++ as my compiler

1

There are 1 best solutions below

0
Alan Birtles On

The result of std::type_info::name is implementation defined.

It looks like you're using some form of Itanium based compiler, see https://itanium-cxx-abi.github.io/cxx-abi/abi-mangling.html.

F is a function, f is the float return type, ic are the int and char arguments, E is the end of the argument list.