6/typeinfo.c
/* gets the byte offset of 'memb' within the aggregate type 'aggr' */
gets the byte offset of 'memb' within the aggregate type 'aggr'
gets the byte offset of ' memb ' within the aggregate type ' aggr '
ssize_t tyoffset(Type *ty, Node *memb)
{
    size_t i;
    size_t off;
    ty = tybase(ty);
    if (ty->type == Typtr)
        ty = tybase(ty->sub[0]);
    assert(ty->type == Tystruct);
    off = 0;
    for (i = 0; i < ty->nmemb; i++) {
        off = alignto(off, decltype(ty->sdecls[i]));
        if (!strcmp(namestr(memb), declname(ty->sdecls[i])))
            return off;
        off += size(ty->sdecls[i]);
    }
    die("bad offset");
    return 0;
}
ssize_t tyoffset ( Type * ty , Node * memb ) { size_t i ; size_t off ; ty = tybase ( ty ) ; if ( ty -> type == Typtr ) ty = tybase ( ty -> sub [ 0 ] ) ; assert ( ty -> type == Tystruct ) ; off = 0 ; for ( i = 0 ; i < ty -> nmemb ; i ++ ) { off = alignto ( off , decltype ( ty -> sdecls [ i ] ) ) ; if ( ! strcmp ( namestr ( memb ) , declname ( ty -> sdecls [ i ] ) ) ) return off ; off += size ( ty -> sdecls [ i ] ) ; } die ( " " ) ; return 0 ; }
gets the byte offset of 'memb' within the aggregate type 'aggr'
gets the byte offset of ' memb ' within the aggregate type ' aggr '