Topic: What is the typeid of a function (not a function call)?
Author: swf@elsegundoca.ncr.com (Stan Friesen)
Date: 1996/11/12 Raw View
In article <55o19v$6o5@news.service.uci.edu>, dan@cafws4.eng.uci.edu
(Dan Harkless) writes:
|> 1. I don't understand what implication not doing lvalue-to-rvalue has.
I believe one implication is that it does not actually perform a dereference
operations when applied to an expression like '*v'. Thus 'v' need not
contain a valid pointer in order to use 'typeid(*v)'.
|> 2. Not doing array-to-pointer seems to indicate that this code:
|>
|> int a[3];
|>
|> cout << typeid(a).name() << endl;
|> cout << (typeid(a) == typeid(int*)) << endl;
|>
|> will produce:
|>
|> int[3]
|> 0
It does seem like that to me as well.
Borland looks broken to me too.
--
swf@elsegundoca.ncr.com sarima@ix.netcom.com
The peace of God be with you.
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: dan@cafws4.eng.uci.edu (Dan Harkless)
Date: 1996/11/13 Raw View
Stan Friesen <swf@elsegundoca.ncr.com> writes:
>In article <55o19v$6o5@news.service.uci.edu>, dan@cafws4.eng.uci.edu
>(Dan Harkless) writes:
>
>|> 1. I don't understand what implication not doing lvalue-to-rvalue has.
>
>I believe one implication is that it does not actually perform a dereference
>operations when applied to an expression like '*v'. Thus 'v' need not
>contain a valid pointer in order to use 'typeid(*v)'.
Actually, it will dereference the v if v is a polymorphic type. If it
isn't, it won't dereference the pointer thanks to the wording "The expression
is not evaluated", not thanks to lvalue-to-rvalue conversion not being done,
right?
Dan Harkless
dan@unitech.com
Unitech Research, Inc.
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: dan@cafws4.eng.uci.edu (Dan Harkless)
Date: 1996/11/05 Raw View
[This article has been posted and then reposted by the moderator but has never
showed up at either of the (unrelated) sites at which I receive news. I am
trying again...]
Hello. My company is currently upgrading our compiler to incorporate RTTI
based on the latest version of the standard. Unfortunately, 5.2.8, Type
identification, is quite vague for many cases.
The C++ Draft Standard states in 5.2.8-3: "When typeid is applied to an
expression other than an lvalue of polymorphic class type, the result refers
to a type_info object representing the static type of the expression.
Lvalue-to-rvalue (4.1), array-to-pointer (4.2), and function-to-pointer (4.3)
conversions are not applied to the expression.
1. I don't understand what implication not doing lvalue-to-rvalue has.
2. Not doing array-to-pointer seems to indicate that this code:
int a[3];
cout << typeid(a).name() << endl;
cout << (typeid(a) == typeid(int*)) << endl;
will produce:
int[3]
0
However, this is not what Borland C++ 5.0 and Microsoft Visual C++ 4.2 do.
They produce:
int*
1
It sounds like they are not following 5.2.8-3, right?
3. Not doing function-to-pointer conversions leaves a real quandry for what
to do for the following case:
double f(int);
double (*f_ptr)(int);
cout << typeid(f(1)).name() << endl;
cout << typeid(f).name() << endl;
cout << typeid(f_ptr).name() << endl;
cout << (typeid(f) == typeid(f_ptr)) << endl;
We are guessing:
double
double()(int) // or double (int)
double(*)(int)
0
However, this is not what Borland C++ 5.0 and Microsoft Visual C++ 4.2 do.
They give:
double
double(*)(int)
double(*)(int)
1
Again, sounds like they are not following 5.2.8-3. We realize the .name()
member function is implementation-defined, but what would the preferred
.name() for f above be? "double()(int)"? "double (int)"?
Regards,
Dan Harkless
Unitech Research, Inc.
dan@unitech.com
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]