{.emit: """
#include <stdlib.h>
typedef struct {
int x;
} Parent;
typedef struct {
int y;
} Child;
Child *child_new() { return malloc(sizeof(Child)); }
""".}
type
Parent {.importc, nodecl, pure, inheritable.} = object
x: cint
Child {.importc, nodecl, pure.} = object of Parent
y: cint
proc newChild(): ptr Child {.importc: "child_new".}
let c = newChild()
echo c.x # error: ‘Child’ has no member named ‘Sup’
let p: ptr Parent = c # error: ‘Child’ has no member named ‘Sup’
I found that my C code is missing a line...
typedef struct {
Parent base;
int y;
} Child;
type
Parent {.importc, nodecl.} = object
x: cint
Child {.importc, nodecl.} = object
base: Parent
y: int
var c: Child
echo c.base.x
let p = cast[ptr Parent](addr c)