typeinfo comparison - 'is' or '=='?

Anders F Björklund afb at algonet.se
Sun May 7 10:49:15 PDT 2006


Burton Radons wrote:

>> Well, not "wrong" - it is just not portable ? But changing it from 'is'
>> over to use '==' instead would make it work in more places than it does.
> 
> The opCmp method in almost all of the TypeInfo are completely inadequate 
> for their task; for example, according to DMD "typeid (void *) == typeid 
> (char *)"; any chained type (pointers, arrays, delegates, functions) has 
> this problem, which would allow for data corruption in unboxing. That's 
> why I used "is" instead: it's better to reject an unboxing than to do it 
> wrong.

That is a much more valid reason to use "is" than the performance one...

>> So I think that Phobos should be changed.
> 
> std.boxer should be changed but only after TypeInfo has been fixed. I 
> sent Walter a partial fix* for it (which was faster too) shortly after 
> writing std.boxer; I don't know why he didn't incorporate it. Walter?
> 
> * Delegates and functions cannot be truly fixed until the TypeInfo 
> includes parameter information.

Yes, if the typeid for pointer types could be fixed, that would be good.
(as I know that was one of the major problems for the "readf" methods)

--anders



More information about the Digitalmars-d mailing list