Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binding flag enums #650

Open
ericmarkmartin opened this issue Jul 2, 2020 · 2 comments
Open

Binding flag enums #650

ericmarkmartin opened this issue Jul 2, 2020 · 2 comments

Comments

@ericmarkmartin
Copy link

In #598, there is some discussion of how to correctly bind a c enum that is used as a flag. In it, @yallop helpfully suggests that the enum construct can be used to obtain a view into the correct width c type. Here, he gives as an example the following code snippet:

let enum_flags = enum "flags" [] ~unexpected:(fun x -> x)

upon which we can build a view that correctly maps a list of flags into the enum and vice-versa. I am unsure if @yallop meant to literal pass enum an empty list or not, but it seems to be the case that if one passes enum an empty list the view created by enum will throw a Not_found upon receiving any value, as it will vacuously never match an element on the lhs of a tuple in the passed alist.

Is there a way we can use the enum construct to correctly identify the c type the compiler will use to represent a given enum without running into this issue?

@lpw25

@yallop
Copy link
Owner

yallop commented Jul 10, 2020

Thank you for the report, @ericmarkmartin. I think you're quite right about this problem.

I have a proposal for an unbundled interface which I think will provide what you need. I'll write it up soon and add a link here.

@yallop
Copy link
Owner

yallop commented Jul 15, 2020

#652 proposes support for using integer types of unknown sizes, which includes support for binding enums as integer types.

I think it's a more suitable basis for using enums as flagsets than the current enum operation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants