Situation: checking state in C ++ or C # with many criteria:
if (condition1 && condition2 && condition3) {
I have always believed that the sequence in which these checks are performed is not guaranteed. Therefore, this is not necessarily the first condition1, then condition 2, and only then condition 3. I found out in my time with C ++. I think they told me that I read it somewhere.
Until I know that I always wrote safe code to account for possible zero-point pointers in the following situation:
if ((object != null) && (object.SomeFunc() != value)) {
So I wrote:
if (object != null) { if (object.SomeFunc() != value) {
Since I was not sure that the non-null check would be executed first, and only then would the instance method be called to perform the second check.
Now our greatest community minds are telling me that the sequence in which these checks are performed will be performed from left to right.
I am very surprised. Is this really true for C ++ and C #?
Has anyone else heard the version I heard before?
c ++ c # non-deterministic deterministic
User
source share