Archive 17/01/2023.

Curious about offsetof() in Urho3D

izackp

There seems to be frequent use of offsetof() inside of the Urho3D engine. I’m surprised that this hasn’t caused any problems considering its documented to be only valid for standard layout classes (c++11; cplusplus(dot)com/reference/cstddef/offsetof/). Urho3D doesn’t seem to care and utilizes this function for classes that are not standard layout classes because they implement virtual functions.

So can anyone explain whats going on? is there problems because of this? or perhaps it just happens to work? or maybe I’m wrong?

cadaver

I’m aware that it’s a violation, but so far it has not caused problems, because Urho’s class hierarchy is for the most part simple: no virtual inheritance, and very limited use of multiple inheritance. It’s something to be careful with, though: always take the offset from the actual class, and not the base class. The ideal would be to move away from it where possible to using accessor functions, for both scripting and attributes.

izackp

Cool, thanks for the info.

I guess it does ‘just work’ of you’re really careful. I guess I’ll just have to include that in my unit tests xD.

weitjong

That is a good idea. At the moment we only perform functional tests in our Continuous Integration build jobs on Travis-CI.org. We have whipped our CI build into shape quite significantly lately to solve a few unexplained intermittent build error issues, thinking the fault was on our side at first but as it turns out more and more evidences come out to point that the fault is actually on Travis-CI.org side. As a result, I reckon we now have some legroom to include a few unit tests as part of our CI build :slight_smile:, and even more so once Travis-CI.org finally pull themselves together to fix their upstream issues. It would be great to see how you or others perform unit tests and to see how we can consolidate them together. Sorry for the off topic discussion.