Why D is annoying =P

H. S. Teoh hsteoh at quickfur.ath.cx
Wed Oct 24 19:38:39 PDT 2012


On Wed, Oct 24, 2012 at 10:12:48PM -0400, Jonathan M Davis wrote:
> On Wednesday, October 24, 2012 13:31:14 Walter Bright wrote:
> > The default compare for structs is a bit compare of the contents.
> 
> Which definitely seems inherently broken. Doing that only works if the
> struct only contains integral types, character types, or bool. Nothing
> else will compare properly that way. It really needs to work like
> arrays do (or are supposed to anyway) and compare each member
> according to == and only fallback to an outright bitwise compare when
> it knows that the results would be identical (i.e. because all of the
> members are integral types, character types, bool, or other structs
> which hold only integral types, character types, or bool - be it
> directly or in other structs that they hold). Bitwise comparison is
> the is operator's job, not ==.
[...]

The built-in AA's suffer from the same problem. Which is why sometimes,
if you use a struct as key, entries cannot be found because the key
being looked up is bitwise different from any key in the AA, but they
have the same value (e.g., the struct has a reference to two distinct
objects that have the same value).


T

-- 
Food and laptops don't mix.


More information about the Digitalmars-d mailing list