This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: result type of an operation betweem signed and unsigned, c++
- From: John Love-Jensen <eljay at adobe dot com>
- To: Dima Sorkin <dima dot sorkin at gmail dot com>, MSX to GCC <gcc-help at gcc dot gnu dot org>
- Date: Tue, 24 Apr 2007 10:46:00 -0500
- Subject: Re: result type of an operation betweem signed and unsigned, c++
- Reinject: from source ([192.150.20.142]) by exprod6ob55.postini.com ([64.18.5.12]) with SMTP; Tue, 24 Apr 2007 08:46:12 PDT
- Reinject: from exprod6og56.obsmtp.com (exprod6ob56.obsmtp.com [64.18.1.192]) by outbound-smtp-2.corp.adobe.com (8.12.10/8.12.10) with SMTP id l3OFkASd010989 for <gcc-help@gcc.gnu.org>; Tue, 24 Apr 2007 08:46:10 -0700 (PDT)
Hi Dima,
> 2) Is there some way to convert a type of an expression into
> _readable_ string ("typeof"), to debug such things ?
- - - - - - - - - - - - - - - - - - - - - - >8 - - -
#include <iostream>
#include <typeinfo>
int main()
{
int i(0);
unsigned u(1);
bool isPos( i-u > 0 );
int res(i-u);
std::cout << i-u << ' ' << isPos << ' ' << res << '\n';
std::cout << typeid(i-u).name()
<< ' ' << typeid(isPos).name()
<< ' ' << typeid(res).name() << '\n';
}
- - - - - - - - - - - - - - - - - - - - - - >8 - - -
Note: the name generated in the typeinfo varies by compiler. Could,
technically (but that would be silly) vary from run-to-run of the binary.
Some may use single characters. Others more human-friendly names. Others
could use UUID.
If you *really* need human (or developer) readable names, you can make a
std::map<std::string, std::string> of the ones you care about via...
MySpiffyTypeMap[typeid(unsigned)] = "unsigned int";
MySpiffyTypeMap[typeid(int)] = "signed int";
MySpiffyTypeMap[typeid(bool)] = "bool";
HTH,
--Eljay