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

MU_ENUM_VALUE_COUNT is misleading #31

Open
anporumb opened this issue Oct 15, 2019 · 0 comments
Open

MU_ENUM_VALUE_COUNT is misleading #31

anporumb opened this issue Oct 15, 2019 · 0 comments
Assignees

Comments

@anporumb
Copy link
Collaborator

Given the following enum definition:

#define BSDL_METADATA_DATA_RESULT_VALUES \
    BSDL_METADATA_DATA_FAILURE, \
    BSDL_METADATA_DATA_INVALID, \
    BSDL_METADATA_DATA_OK \

MU_DEFINE_ENUM(BSDL_METADATA_DATA_RESULT, BSDL_METADATA_DATA_RESULT_VALUES)

One would reasonably write:

int n=MU_ENUM_VALUE_COUNT(BSDL_METADATA_DATA_RESULT);

However, "n" will not have the expected value (something out of range of the enum values), instead will get the value BSDL_METADATA_DATA_INVALID, which is well within the range of the enum values.

I suspect this could be fixed in several ways:

  1. document the intended usage of MU_ENUM_VALUE_COUNT.
  2. "magically" make the construct fail at compile time

Best Regards,
Andrei Porumb

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