Division by zero when comparing using a pointer to a derived class instance

Discussions about product bugs & problems!
Note: This is no replacement for the Official ETM Support!
Search

Post Reply
1 post • Page 1 of 1
dvribeira
Posts: 24
Joined: Mon Mar 18, 2019 10:53 am

Division by zero when comparing using a pointer to a derived class instance

Post by dvribeira » Wed Feb 05, 2020 3:23 pm

So I have found this issue (WinCC OA 3.16 P016):
  • Comparing two instances of the same class works as expected, obviously.
  • Comparing an instance of a superclass against an instance of a subclass works, comparing the superclass properties only.
  • Comparing an instance of a superclass to a pointer to a superclass instance works.
  • Comparing two pointers containing two instances of exactly the same class works.
  • Comparing an instance of the superclass against a pointer to a subclass instance does not work: division by zero error.
  • Comparing two pointers containing one superclass instance and one subclass instance does not work: division by zero error.
  • Comparing two pointers to superclass but containing two subclass instances works but this time comparing both the superclass and the subclass properties. This is not an error but it is interesting that it would behave different than the second case in this list.
  • Comparing two pointers to the same subclass work normally.
  • Did not test comparing instances of different subclasses or pointers to them.
You can find below a little code snippet to try this.

Code: Select all

class A {
    int an_int;
    public A(int val) {
        an_int = val;
    }
};

class B : A {
    int another_int;
    public B(int val1, int val2) : A(val1) {
        another_int = val2;
    }
};

main () {
    A a = new A(1);
    A b = new B(1, 2);
    DebugN(a == b);
    shared_ptr<A> p_a = new A(1);
    shared_ptr<A> p_b = new B(1, 2);
    shared_ptr<A> p_c = new B(1, 3);
    DebugN(a == p_a);
    DebugN(a == p_b);
    DebugN(p_a == p_b);
    DebugN(p_b == p_c);
}

Cheers,
Daniel

Post Reply
1 post • Page 1 of 1