union&enum的用法

enum utype { INTEGER=1, STRING=2, GNUMBERS=3 };

struct u_tag {

    enum utype utype;   /*  the union's discriminant  */

    union {

        int ival;

        char *pval;

        struct gnumbers gn;

    } uval;

};

 

struct xdr_discrim u_tag_arms[4] = {

    { INTEGER, xdr_int },

    { GNUMBERS, xdr_gnumbers }

    { STRING, xdr_wrap_string },

    { __dontcare__, NULL }

    /*  always terminate arms with a NULL xdr_proc  */

};

bool_t

xdr_u_tag(xdrs, utp)

    XDR *xdrs;

    struct u_tag *utp;

{

    return(xdr_union(xdrs, &utp->utype, &utp->uval,

        u_tag_arms, NULL));

}

posted @ 2010-12-30 13:58  BloodAndBone  Views(291)  Comments(0Edit  收藏  举报