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" !!
}
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"

 be in different points in memory, they cannot have the same internal

 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"

 be in different points in memory, they cannot have the same internal

 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

 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


 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.

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.

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

 better approach. === is for reference comparisons.

This is what we wanted for soo long. Thanks. Ciao
Jun 03 2002