9

I'm currently trying to debug a piece of simple code and wish to see how a specific variable type changes during the program.

I'm using the typeinfo header file so I can utilise typeid.name(). I'm aware that typeid.name() is compiler specific thus the output might not be particularly helpful or standard.

I'm using GCC but I cannot find a list of the potential output despite searching, assuming a list of typeid output symbols exist. I don't want to do any sort of casting based on the output or manipulate any kind of data, just follow its type.

#include <iostream>
#include <typeinfo>

int main()
{ 
    int a = 10;
    cout << typeid(int).name() << endl;
}

Is there a symbol list anywhere?

enedil
  • 1,605
  • 4
  • 18
  • 34
aLostMonkey
  • 594
  • 1
  • 6
  • 14
  • it might be worth noting that it's GCC bundled with MinGW. – aLostMonkey Oct 07 '10 at 16:10
  • 1
    if you just want to follow types, then how about `if (typeid(a) == typeid(int)) { /* action */ }`? – Donotalo Oct 07 '10 at 16:10
  • What are you trying to do? What do you mean by symbol list exactly? – sellibitze Oct 07 '10 at 16:16
  • 2
    "... variable type changes...". Er... In C++ variable types never change. Variable always have the type it was first declared with. – AnT stands with Russia Oct 07 '10 at 16:19
  • possible duplicate of [Unmangling the result of std::type_info::name](http://stackoverflow.com/questions/281818/unmangling-the-result-of-stdtype-infoname) – Mike Seymour Oct 07 '10 at 16:25
  • I'm checking whether something has a remainder or not. I was passing the modulus operator a double for its left operand thus an error. The code I finally got working is using vector::size_type. This is being defined as a double but it works when passed as a modulus operand. Which is why I want to check the type later on. As for symbols, I just mean the not-too-cryptic output letters GCC decides to use. – aLostMonkey Oct 07 '10 at 16:55

1 Answers1

18

I don't know if such a list exists, but you can make a small program to print them out:

#include <iostream>
#include <typeinfo>

#define PRINT_NAME(x) std::cout << #x << " - " << typeid(x).name() << '\n'

int main()
{
    PRINT_NAME(char);
    PRINT_NAME(signed char);
    PRINT_NAME(unsigned char);
    PRINT_NAME(short);
    PRINT_NAME(unsigned short);
    PRINT_NAME(int);
    PRINT_NAME(unsigned int);
    PRINT_NAME(long);
    PRINT_NAME(unsigned long);
    PRINT_NAME(float);
    PRINT_NAME(double);
    PRINT_NAME(long double);
    PRINT_NAME(char*);
    PRINT_NAME(const char*);
    //...
}
UncleBens
  • 40,819
  • 6
  • 57
  • 90