Skip to content

MU_ENUM_VALUE_COUNT is misleading #31

Description

@anporumb

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

Metadata

Metadata

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions