Extension: Object Inheritance

Example

struct Foo {
  int a;
};
struct Bar {
  struct Foo foo;
  int b;
};

void f(Foo*);
void g(Bar*);

Bar *x;
f(x);
g(x);
x->a + x->b;

Syntax & Semantics

If struct Bar has as its first member a struct Foo, then a struct Bar* can be implicitly converted to struct Foo*, either to pass to a function or to look up a data member.

This extension is intended to accomodate already-existing object-oriented C programs (especially libraries) without modification to their source code.

See also: the anonymous structure members extension.

Implementation

Not implemented.