[PATCH 3/3] argparse: use enums to remove max-value defines in lists
fengchengwen
fengchengwen at huawei.com
Wed Jun 4 03:22:06 CEST 2025
It looks more clear and user-friendly for splitting the flag.
Acked-by: Chengwen Feng <fengchengwen at huawei.com>
On 2025/5/27 17:21, Bruce Richardson wrote:
> The use of lists of #defines with _MAX entries at the end causes issues
> for ABI compatibility as those MAX values often leak through to
> applications and can cause issues when changed.
>
> We can rework the code to increase type safety by splitting the flags
> field and using enums for each set of values explicitly:
>
> * One enum for whether an argument takes a parameter or not (or
> optionally takes one)
> * One enum for the type of the argument.
> * A separate flags field for any additional info - right now this is
> only to indicate an argument can appear more than once.
>
> The use of the MAX field is no longer necessary using the enums as we
> can use an inline function with a switch statement to check for valid
> values. Compilers like GCC will warn when an enum value is missing from
> the switch statement, easing future maintenance if enum values are
> added.
>
> Signed-off-by: Bruce Richardson <bruce.richardson at intel.com>
More information about the dev
mailing list