menu_xxx_NUM_CHOICES should not be part of the enum

Bug #1580972 reported by Ben Franksen
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
EPICS Base
Fix Released
Low
Andrew Johnson

Bug Description

In base-3.15 (and perhaps later versions), the C enumerations generated for a menu dbd contain an additional menu_xxx_NUM_CHOICES, example:

typedef enum {
    menuCvtInitStateDone /* Done */,
    menuCvtInitStateInProgress /* InProgress */,
    menuCvtInitStateAgain /* Again */,
    menuCvtInitStateError /* Error */,
    menuCvtInitState_NUM_CHOICES
} menuCvtInitState;

This is not a good idea IMNSHO: modern C compilers (gcc in particular) issue warnings for switch statements that do not handle all cases of an enum. This is very useful for refactoring or for adding new features, since it shows you all the places where a new case is not yet handled. The additional ..._NUM_CHOICES item defeats this: either you must live with code that issues bogus warnings for the _NUM_CHOICES item or you add a default case everywhere, effectively disabling these warnings.

Here is what I think should be generated instead:

typedef enum {
    menuCvtInitStateDone /* Done */,
    menuCvtInitStateInProgress /* InProgress */,
    menuCvtInitStateAgain /* Again */,
    menuCvtInitStateError /* Error */
} menuCvtInitState;

#define menuCvtInitState_NUM_CHOICES (menuCvtInitStateError+1)

Revision history for this message
Andrew Johnson (anj) wrote :

Agreed, although I choose to make it very slightly harder for someone to hand-edit the generated menu.h file.

Ralph, would you like this fix committed immediately?

Changed in epics-base:
status: New → In Progress
importance: Undecided → Low
assignee: nobody → Andrew Johnson (anj)
Revision history for this message
Andrew Johnson (anj) wrote :

(Set the bug target to the 3.15.4 milestone if you want it included there)

Revision history for this message
Ralph Lange (ralph-lange) wrote :

Yes, please.

Changed in epics-base:
milestone: none → 3.15.4
Andrew Johnson (anj)
Changed in epics-base:
status: In Progress → Fix Committed
Changed in epics-base:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.