@defstx @mycontainerof(p, tn, f) { #`{ { @local fld, _tn, type, tmp; _tn = #,tn; tmp = #,p; type = looktype(domof(tmp), _tn); if(isnil(type)) error("undefined type %t", _tn); fld = lookfield(type, #,(#val(stxid(f)))); if(isnil(fld)) error("undefined field %a", #,(#val(stxid(f)))); type = mkctype_ptr(type, nsptr(domof(tmp))); {type}((void*)tmp - fieldoff(fld)); } }; } ns = @names c64le { struct X { @0x0 int x; @0x4 int y; @0x8 int z; @0xc; }; }; dom = mkdom(ns, mknas()); p = (struct X*){dom}0; printf("p is %t 0x%x\n", @typeof(p), p); q = &p->y; printf("q is %t 0x%x\n", @typeof(q), q); r = @mycontainerof(q, @typename(struct X), y); printf("r is %t 0x%x\n", @typeof(r), r); //p = (struct X*){dom}0; //printf("p is %t 0x%x\n", @typeof(p), p); //q = &p->y; //printf("q is %t 0x%x\n", @typeof(q), q); //r = @mycontainerof(q, struct dom`X, y); //printf("r is %t 0x%x\n", @typeof(r), r); //p = (struct X*){dom}0; //printf("p is %t 0x%x\n", @typeof(p), p); //q = &p->z; //printf("q is %t 0x%x\n", @typeof(q), q); //r = @mycontainerof(q, struct dom`X, y); //printf("r is %t 0x%x\n", @typeof(r), r);