Pre-RFC: anonymous struct and union types

I need this as well. I’m working on FFI bindings to the libbinder android library. It has a few structs that look like

struct flat_binder_object {
	struct binder_object_header	hdr;
	__u32				flags;

	/* 8 bytes of data. */
	union {
		binder_uintptr_t	binder;	/* local object */
		__u32			handle;	/* remote object */
	};

	/* extra data associated with local object */
	binder_uintptr_t	cookie;
};

or even deeper nesting of struct/union/struct. This leads bindgen to generate some fairly annoying code :

#[repr(C)]
#[derive(Copy)]
pub struct flat_binder_object {
    pub type_: u32,
    pub flags: u32,
    pub __bindgen_anon_1: flat_binder_object__bindgen_ty_1,
    pub cookie: binder_uintptr_t,
}

#[repr(C)]
#[derive(Copy)]
pub union flat_binder_object__bindgen_ty_1 {
    pub binder: binder_uintptr_t,
    pub handle: u32,
}

This is obviously sub-par. Having unlabeled fields would allow bindgen to generate “good” bindings.

I’m planning to try to put a full RFC for this together soon.

I plan to make it extremely minimal, introducing as little syntax as possible. In particular, I don’t plan to push for the ability to declare an anonymous type for a named field (the fieldname: struct { .. }, syntax), only for the ability to group fields together without introducing a name for that group.

3 Likes

Please feel free to poke me if you want feedback on the siginfo_t use case.

Now posted as RFC 2012.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.