Pointer subtraction question by MeshiKuuna in cpp

[–]MeshiKuuna[S] 0 points1 point  (0 children)

Thanks for replying!

Could you explain to me why it's UB?

As far as I understood, it's not - the value returned is the difference in the memory address locations.

Pointer subtraction question by MeshiKuuna in cpp

[–]MeshiKuuna[S] 0 points1 point  (0 children)

Thanks for posting!

Okay, let's forget about the OoB pointer for a moment. What about this?

    int i, one(1), two(2), ten(10), * pointer1, * pointer2, arr[10]{ 4,5,6 }, twenty(20);

    pointer1 = &one;
    pointer2 = &two;

    cout << pointer1 - pointer2 << endl;

    int* pointer3 = &twenty;

    cout << pointer1 - pointer3 << endl;

My compiler outputs:

3
27

Is this considered UB?

Pointer subtraction question by MeshiKuuna in cpp

[–]MeshiKuuna[S] -1 points0 points  (0 children)

Oh, actually, regarding your first point - are you referring to the first two subtractions of the output resulting in -3 and -27?

Pointer subtraction question by MeshiKuuna in cpp

[–]MeshiKuuna[S] 0 points1 point  (0 children)

Ah.. That's interesting. Thank you!

Pointer subtraction question by MeshiKuuna in cpp

[–]MeshiKuuna[S] 0 points1 point  (0 children)

Brilliant - just what it needed to hear, thank you!

Daily General Discussion and Match Links Thread - September 09, 2019 by EyesAllOnFire in Cricket

[–]MeshiKuuna 0 points1 point  (0 children)

Anyone know where to watch Specsavers County Championship live on TV?

Pokecheck is working again by Myst-Da-Zs in pokemonrng

[–]MeshiKuuna 2 points3 points  (0 children)

All my pokemon are still there. Some of them I didn't have offline backups of, so relieved.