www.digitalmars.com         C & C++   DMDScript  

D - Array comparisons bug - arraytest.d

reply Mike Wynn <Mike_member pathlink.com> writes:
Is this a known bug ?
Attached is small test prog that shows the problem.
char[] a = <whatever>;
char[] b = <whatever-else>;

if ( a == b )
{
// this code will be run as if the line above was
// if (a.length == b.length && a[0] == b[0])
// so this implies "pos" == "pzz" !!
}


begin 0644 arraytest.d




M)PT*<W1R,B`]/2!S='(Q(&ES("=T<G5E)PT*<W1R,B`]/2!S='(S(&ES("=F

M:7, )V9A;'-E)PT*<W1R,R`]/2!S='(R(&ES("=F86QS92<-"G-T<C, /3T 

M-"`]/2!S='(R(&ES("=F86QS92<-"G-T<C0 /3T <W1R,R!I<R`G9F%L<V4G

M:70 ;&%S=$-O;7!297-U;'0 *0T*>PT*"6-H87);72!T=B`](")T<G5E(CL-
M" EC:&%R6UT 9G8 /2`B9F%L<V4B.PT*"7)E='5R;B`H;&%S=$-O;7!297-U



M(")Z>GIZ>GHB.PT*"6-H87);72!S='(T(#T (G!U8FQI(CL-" T*"7!R:6YT
M9B  (G-T<C$ :7, )R5S)UQN(BP *&-H87(J*7-T<C$ *3L-" EP<FEN=&8H

M<W1R,R!I<R`G)7,G7&XB+"`H8VAA<BHI<W1R,R`I.PT*"7!R:6YT9B  (G-T


M>2!S=')I;F< =&AE(&-O;7` <V5E;7, =&\ 8F4 ;VYL>0T*"71H92!F:7)S

M="`]("AS='(Q(#T]('-T<C(I.PT*"7!R:6YT9B  (G-T<C$ /3T <W1R,B!I
M<R`G)7,G7&XB+"`H8VAA<BHI<W1R5F%L*"!L87-T0V]M<%)E<W5L="`I("D[

M(")S='(Q(#T]('-T<C, :7, )R5S)UQN(BP *&-H87(J*7-T<E9A;"  ;&%S



M<W5L="`]("AS='(R(#T]('-T<C$I.PT*"7!R:6YT9B  (G-T<C( /3T <W1R
M,2!I<R`G)7,G7&XB+"`H8VAA<BHI<W1R5F%L*"!L87-T0V]M<%)E<W5L="`I

M=&8H(")S='(R(#T]('-T<C, :7, )R5S)UQN(BP *&-H87(J*7-T<E9A;"  



M<%)E<W5L="`]("AS='(S(#T]('-T<C$I.PT*"7!R:6YT9B  (G-T<C, /3T 
M<W1R,2!I<R`G)7,G7&XB+"`H8VAA<BHI<W1R5F%L*"!L87-T0V]M<%)E<W5L

M<FEN=&8H(")S='(S(#T]('-T<C( :7, )R5S)UQN(BP *&-H87(J*7-T<E9A



M0V]M<%)E<W5L="`]("AS='(T(#T]('-T<C$I.PT*"7!R:6YT9B  (G-T<C0 
M/3T <W1R,2!I<R`G)7,G7&XB+"`H8VAA<BHI<W1R5F%L*"!L87-T0V]M<%)E

M" EP<FEN=&8H(")S='(T(#T]('-T<C( :7, )R5S)UQN(BP *&-H87(J*7-T



/"7)E='5R;B`P.PT*?0T*
`
end
Jun 02 2002
parent reply "Walter" <walter digitalmars.com> writes:
"Mike Wynn" <Mike_member pathlink.com> wrote in message
news:add42g$4pa$1 digitaldaemon.com...
 Is this a known bug ?
 Attached is small test prog that shows the problem.
 char[] a = <whatever>;
 char[] b = <whatever-else>;

 if ( a == b )
 {
 // this code will be run as if the line above was
 // if (a.length == b.length && a[0] == b[0])
 // so this implies "pos" == "pzz" !!
 }
That's intended behavior. To get the behaviour you're looking for, use === (that's 3 =).
Jun 02 2002
parent reply Russ Lewis <spamhole-2001-07-16 deming-os.org> writes:
Walter wrote:

 "Mike Wynn" <Mike_member pathlink.com> wrote in message
 news:add42g$4pa$1 digitaldaemon.com...
 Is this a known bug ?
 Attached is small test prog that shows the problem.
 char[] a = <whatever>;
 char[] b = <whatever-else>;

 if ( a == b )
 {
 // this code will be run as if the line above was
 // if (a.length == b.length && a[0] == b[0])
 // so this implies "pos" == "pzz" !!
 }
That's intended behavior. To get the behaviour you're looking for, use === (that's 3 =).
???????? I thought that == was to compare the references! Since "pos" and "pzz" must be in different points in memory, they cannot have the same internal pointer, and thus the test should fail, right? -- The Villagers are Online! http://villagersonline.com .[ (the fox.(quick,brown)) jumped.over(the dog.lazy) ] .[ (a version.of(English).(precise.more)) is(possible) ] ?[ you want.to(help(develop(it))) ]
Jun 02 2002
next sibling parent reply "Alix Pexton" <Alix seven-point-star.co.uk> writes:
 char[] a = <whatever>;
 char[] b = <whatever-else>;

 if ( a == b )
 {
 // this code will be run as if the line above was
 // if (a.length == b.length && a[0] == b[0])
 // so this implies "pos" == "pzz" !!
 }
That's intended behavior. To get the behaviour you're looking for, use
===
 (that's 3 =).
???????? I thought that == was to compare the references! Since "pos" and "pzz"
must
 be in different points in memory, they cannot have the same internal
pointer,
 and thus the test should fail, right?
The test a[0] == b[0] compares the values in the first element of the two arrays. a[0] === b[0] compares the references to the first element of the two arrays. I think that's right... Alix Pexton...
Jun 02 2002
parent "anderson" <anderson firestar.com.au> writes:
if (a == b) doesn't compare refferences

If that's correct, it's going to cause a nightmare in porting. And I know
this has readly been fought out. On the otherhand I'd encourage programmers
away from using pointers.


"Alix Pexton" <Alix seven-point-star.co.uk> wrote in message
news:01c20a8a$fec54160$fe247ad5 jpswm...
 char[] a = <whatever>;
 char[] b = <whatever-else>;

 if ( a == b )
 {
 // this code will be run as if the line above was
 // if (a.length == b.length && a[0] == b[0])
 // so this implies "pos" == "pzz" !!
 }
That's intended behavior. To get the behaviour you're looking for, use
===
 (that's 3 =).
???????? I thought that == was to compare the references! Since "pos" and "pzz"
must
 be in different points in memory, they cannot have the same internal
pointer,
 and thus the test should fail, right?
The test a[0] == b[0] compares the values in the first element of the two arrays. a[0] === b[0] compares the references to the first element of the two arrays. I think that's right... Alix Pexton...
Jun 02 2002
prev sibling parent reply "Walter" <walter digitalmars.com> writes:
"Russ Lewis" <spamhole-2001-07-16 deming-os.org> wrote in message
news:3CFA9191.EE2B49FA deming-os.org...
 ????????
 I thought that == was to compare the references!
It used to be. Now it's a deep compare, as everyone convinced me that was a better approach. === is for reference comparisons.
Jun 02 2002
next sibling parent reply "Pavel Minayev" <evilone omen.ru> writes:
"Walter" <walter digitalmars.com> wrote in message
news:adeq4k$80d$1 digitaldaemon.com...

 "Russ Lewis" <spamhole-2001-07-16 deming-os.org> wrote in message
 news:3CFA9191.EE2B49FA deming-os.org...
 ????????
 I thought that == was to compare the references!
It used to be. Now it's a deep compare, as everyone convinced me that was
a
 better approach. === is for reference comparisons.
Then how does it turn out that "pos" == "psz" (see the first message in the thread)?
Jun 03 2002
parent reply "Walter" <walter digitalmars.com> writes:
"Pavel Minayev" <evilone omen.ru> wrote in message
news:adf7ca$o7m$1 digitaldaemon.com...
 "Walter" <walter digitalmars.com> wrote in message
 news:adeq4k$80d$1 digitaldaemon.com...

 "Russ Lewis" <spamhole-2001-07-16 deming-os.org> wrote in message
 news:3CFA9191.EE2B49FA deming-os.org...
 ????????
 I thought that == was to compare the references!
It used to be. Now it's a deep compare, as everyone convinced me that
was
 a
 better approach. === is for reference comparisons.
Then how does it turn out that "pos" == "psz" (see the first message in the thread)?
The array lengths and contents match. I guess I don't understand what the question is.
Jun 03 2002
parent reply mike.wynn l8night.co.uk writes:
In article <adgof2$2de0$2 digitaldaemon.com>, Walter says...
 Then how does it turn out that "pos" == "psz" (see the first message in
 the thread)?
The array lengths and contents match. I guess I don't understand what the question is.
the contents do not match "pos" is not the same contents as "psz" if you see my first posting D only checks the first element in the array if the lengths match. surely it should check all then element for equality before considering them equal. Mike.
Jun 03 2002
parent "Walter" <walter digitalmars.com> writes:
<mike.wynn l8night.co.uk> wrote in message
news:adh1r5$2ndr$1 digitaldaemon.com...
 In article <adgof2$2de0$2 digitaldaemon.com>, Walter says...
 Then how does it turn out that "pos" == "psz" (see the first message in
 the thread)?
The array lengths and contents match. I guess I don't understand what the question is.
the contents do not match "pos" is not the same contents as "psz" if you see my first posting D only checks the first element in the array if the lengths match. surely it should check all then element for equality before considering them equal.
Yes, it should check all the elements. If it doesn't, it's a bug.
Jun 03 2002
prev sibling parent "Roberto Mariottini" <rmariottini lycosmail.com> writes:
"Walter" <walter digitalmars.com> ha scritto nel messaggio
news:adeq4k$80d$1 digitaldaemon.com...
 "Russ Lewis" <spamhole-2001-07-16 deming-os.org> wrote in message
 news:3CFA9191.EE2B49FA deming-os.org...
 ????????
 I thought that == was to compare the references!
It used to be. Now it's a deep compare, as everyone convinced me that was
a
 better approach. === is for reference comparisons.
This is what we wanted for soo long. Thanks. Ciao
Jun 03 2002