type_info::name question

Alexandre Oliva oliva@dcc.unicamp.br
Mon Sep 21 07:32:00 GMT 1998

Thomas Kunert <kunert@physik.tu-dresden.de> writes:

> Alexandre Oliva wrote:

>> type_info::name *isn't* useful at all, as defined in the standard.  

> ``Implementation defined'' doesn't mean ``as unuseful as possible to
> prevent portability problems'' but ``make the best of it, everybody
> should know about portability''. And if the function does what it's name
> suggests -- giving the name of the type in some readable language -- it
> *is* useful.

Then please tell us what the following program should print [note: it
does not compile with egcs 1.1, only with newer snapshots]:

#include <iostream>
#include <string>
#include <typeinfo>

template <typename T>
struct foo {
  foo() {
    struct test {
      test() { std::cout << typeid(*this).name() << std::endl; }
    } mytest;

main() {
  foo<std::string> bar;

If you can find a readable and portable representation of that, then
you're free to try to implement it within egcs.

>> If you really want a readable representation, I've already
>> explained that it's just a matter of running c++filt or embedding
>> it into your application.

> Of course I can do that, in fact I have done this a long time ago, to
> port some perfectly working code to egcs, but I hate rewriting functions
> from the standard library only because of some weird chosen
> implementation defined values.

On how many other compilers does your perfectly working code would run 
before you ported it to egcs?

Alexandre Oliva
mailto:oliva@dcc.unicamp.br mailto:aoliva@acm.org
Universidade Estadual de Campinas, SP, Brasil

More information about the Gcc mailing list