Thread overview | |||||
---|---|---|---|---|---|
|
July 16, 2004 v0.95, typeid() not comparing correctly | ||||
---|---|---|---|---|
| ||||
The following code in 0.95 does not seem to use typeid values correctly when used in "==" comparisions. This used to work in 0.94.
# import std.string;
# struct Foo{int a,b;};
# struct Bar{float a,b,c;};
#
# void test( ... )
# {
# for (int i = 0; i < _arguments.length; i++)
# {
# std.string.printf("arg=%d f=%d b=%d ",
# _arguments[i], typeid(Foo), typeid(Bar));
#
# if (_arguments[i] == typeid(Bar))
# {
# std.string.printf("Bar\n");
# _argptr += Foo.sizeof;
# }
# else if (_arguments[i] == typeid(Foo))
# {
#
# std.string.printf("Foo\n");
# _argptr += Bar.sizeof;
# }
#
# };
# }
#
# void main( )
# {
# Foo f;
# Bar b;
#
# test(f,b,f,b);
# }
I get ...
arg=4255952 f=4255952 b=4255968 Bar
arg=4255968 f=4255952 b=4255968 Bar
arg=4255952 f=4255952 b=4255968 Bar
arg=4255968 f=4255952 b=4255968 Bar
In other words, I'm passing a Foo, then a Bar, then a Foo then another Bar,
and the output says the right typeid() is in the argument, but the "=="
comparision doesn't pick it up.
--
Derek
Melbourne, Australia
16/Jul/04 5:05:41 PM
|
July 16, 2004 Re: v0.95, typeid() not comparing correctly | ||||
---|---|---|---|---|
| ||||
Posted in reply to Derek Parnell | Derek Parnell wrote:
> The following code in 0.95 does not seem to use typeid values correctly
> when used in "==" comparisions.
You should be able to work around this by using === instead of ==.
-- andy
|
July 17, 2004 Re: v0.95, typeid() not comparing correctly | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andy Friesen | On Fri, 16 Jul 2004 09:28:54 -0700, Andy Friesen wrote: > Derek Parnell wrote: > >> The following code in 0.95 does not seem to use typeid values correctly when used in "==" comparisions. > > You should be able to work around this by using === instead of ==. > Thanks. I retested this with v0.94 and I was wrong. It didn't work with that version either. I then tried the example code in the docs and that failed too. However, I can confirm that "===" and "is" works. I guess I'll use that idiom unless told by Walter not to. -- Derek Melbourne, Australia |
Copyright © 1999-2021 by the D Language Foundation