opCmp on a struct keyed by an array of bytes

Charles Hixson charleshixsn at earthlink.net
Wed Nov 13 19:46:44 PST 2013


On 11/12/2013 04:47 PM, bearophile wrote:
> Charles Hixson:
>
>> I had tried "return bytes.cmp(b.bytes);" , but it didn't occur to me 
>> that the error meant I should have used a copy?  Does this syntax 
>> mean that what's being compared is a dynamic array copy of the 
>> original static array?
>
> They are not copies, just slices. In case of doubts take a look at the 
> generated assembly.
>
> Bye,
> bearophile
>
My assembly is pretty bad, the last one I was fluent in was i6502...I 
was never really fluent in m68000.  And those were back when I was using 
an Apple.

OTOH, while slice is a better term for what I meant...generally when one 
makes a copy of an object, one is only duplicating the pointers to it, 
and that's what I meant.  (Though since the original was a struct, slice 
is a much better term.  Still, on a 64 bit machine the and an 8 byte 
key, the slice is twice the size of the original.  And the only 
benefit(?) is that if the dup was changed, so would be the original.  
Which is what the I thought the const at the end of the declaration was 
supposed to prevent.)

-- 
Charles Hixson



More information about the Digitalmars-d-learn mailing list