No, not only, it also allows the programmer to use MyDataExtended with every function that takes a MyData. However, there obviously is a difference, for example – let's say that we have some function foo(MyData *) that wants to take ownership of MyData... Then we obviously have some issues with using MyDataExtended, unless the ordering is such that MyData comes first.
The advantage is that it's possible to do something like inheritance without the inheritance. E.g.:
type Node struct {
Vector2 position;
RenderFunction *renderFunction;
}
func void Node.addChild(Node *this, Node *childNode) {
...
}
func void Node.render(Node *this, RenderState *state) {
state->push();
... // update render state
for (... all child nodes behind in z order...) {
node->render(state);
}
this->renderFunction(this, state);
for (... all child nodes after in z order...) {
node->render(state);
}
state->pop();
}
type SpriteNode struct {
Node baseNode @(inline)
Texture *texture;
}
func void SpriteNode.init(SpriteNode *this) {
this.renderFunction = SpriteRenderFunction;
}
//
...
Node *scene;
SpriteNode *sprite;
...
scene->addChild(sprite);
scene->render(state);