Thread overview | |||||
---|---|---|---|---|---|
|
August 27, 2012 Comparing pointers with "is" | ||||
---|---|---|---|---|
| ||||
When comparing pointers, is there any difference when writing: int* p1, p2; if(p1 == p2) {...} if(p1 is p2) {...} ? My guess would be that no, there isn't *but*: *Using "==" shows the *intent* of comparing the pointer values? *Using "is" shows the *intent* of checking if the pointed objects are the same? Either that, or is it considered "best practice" to use "is" to compare pointers, because "==" and "is" have a different meaning in the context of using classes? |
August 27, 2012 Re: Comparing pointers with "is" | ||||
---|---|---|---|---|
| ||||
Posted in reply to monarch_dodra | monarch_dodra:
> Either that, or is it considered "best practice" to use "is" to compare pointers,
For two pointers using "==" or "is" is the same. And I don't remember "best practices" about this. If your pointers later risk becoming class references, then it's better to use "is".
Bye,
bearophile
|
August 28, 2012 Re: Comparing pointers with "is" | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | On Monday, 27 August 2012 at 16:33:46 UTC, bearophile wrote:
> monarch_dodra:
>
>> Either that, or is it considered "best practice" to use "is" to compare pointers,
>
> For two pointers using "==" or "is" is the same. And I don't remember "best practices" about this. If your pointers later risk becoming class references, then it's better to use "is".
>
> Bye,
> bearophile
TY for your reply.
|
Copyright © 1999-2021 by the D Language Foundation