Thread overview | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
June 02, 2002 Array comparisons bug - arraytest.d | ||||
---|---|---|---|---|
| ||||
Attachments: | 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" !! } |
June 02, 2002 Re: Array comparisons bug - arraytest.d | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mike Wynn | "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 =). |
June 02, 2002 Re: Array comparisons bug - arraytest.d | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | 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))) ] |
June 02, 2002 Re: Array comparisons bug - arraytest.d | ||||
---|---|---|---|---|
| ||||
Posted in reply to Russ Lewis | > > > 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... |
June 03, 2002 Re: Array comparisons bug - arraytest.d | ||||
---|---|---|---|---|
| ||||
Posted in reply to Alix Pexton | 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... |
June 03, 2002 Re: Array comparisons bug - arraytest.d | ||||
---|---|---|---|---|
| ||||
Posted in reply to Russ Lewis | "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. |
June 03, 2002 Re: Array comparisons bug - arraytest.d | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | "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)? |
June 03, 2002 Re: Array comparisons bug - arraytest.d | ||||
---|---|---|---|---|
| ||||
Posted in reply to Pavel Minayev | "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. |
June 04, 2002 Re: Array comparisons bug - arraytest.d | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | 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. |
June 04, 2002 Re: Array comparisons bug - arraytest.d | ||||
---|---|---|---|---|
| ||||
Posted in reply to mike.wynn | <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. |
Copyright © 1999-2021 by the D Language Foundation