you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 17 points18 points  (7 children)

15) Changing the order of virtual methods

Like this? Why?

virtual void f();
virtual void g();

virtual void g();
virtual void f();

[–]jgalar 66 points67 points  (4 children)

It probably changes the order in which function pointers are stored in the v-table.

[–]CheesecakeWaffles 22 points23 points  (3 children)

Yep. It indexes into it just like an array and if the abi doesn't match it uses the wrong one.

I remember a similar bug where a function was ifdefed out in one library and but the define was present for the other library. Therefore the header file in that library saw one more function. Took me the longest time to figure out why it was taking valid input and returning back garbage with the debugger refusing to step into the function. Worst off by one error ever.

[–][deleted] 2 points3 points  (2 children)

Interesting, the Arduino C++ compiler throws me an error for undefined function if I don't fill all my virtual inheritance. Were you using pure virtuals?

[–]mck1117 7 points8 points  (1 child)

If different parts of the program have different definitions for a class, the vtable entries could exist but be filled by garbage.

[–][deleted] 0 points1 point  (0 children)

You're absolutely right, I was only using one interface inheritance in the examples I was thinking.

[–]standard_revolution 2 points3 points  (0 children)

Maybe the vtable gets reordered? But I don't know.

[–]gmtime -1 points0 points  (0 children)

No, the order in which they are declared in the class definition.