On Wed, 29 Apr 2026 at 13:25, Ankush <[email protected]> wrote: > Reading through the Plan 9 source code, I've noticed enumerations are > always used without a tag. This aspect of the Plan 9 C style isn't covered > by *style(6).* > > Out of curiosity, I'm wondering if anyone knows the reason for the > omission of a tag from all enumerations, and why some source files use a > mixture of enum and #define when the auto-incrementing property of enums > isn't being used. > > In most C code bases, an enum is useful (instead of a macro) because it is > named and the compiler can produce warnings accordingly (e.g. missing enum > case in a switch statement) , or because the values in the enumeration > should be sequential and the compiler can take care of that instead of > requiring the programmer to manually assign values. > > I've picked some examples to make the question more clear, this usage of > enum can be seen all throughout the Plan 9 source: > > From */sys/src/cmd/cc/cc.h* > > enum // no tag, e.g. could be enum OS; why not just use #define for these? > { > Plan9 = 1<<0, > Unix = 1<<1, > Windows = 1<<2, > }; > > > From */**sys/src/9/boot/boot.h* > > enum // Why not #define? The enum isn't named and the values are manually > assigned > { > Statsz= 256, > Nbarg= 16, > }; > > > Hopefully someone out there has more insight on this! > > Thanks, > > Ankush. > *9fans <https://9fans.topicbox.com/latest>* / 9fans / see discussions > <https://9fans.topicbox.com/groups/9fans> + participants > <https://9fans.topicbox.com/groups/9fans/members> + delivery options > <https://9fans.topicbox.com/groups/9fans/subscription> >
Not an authority on the 'why' part of the question, but here's one of the very few examples found in the code base that does use an enum tag. https://github.com/plan9foundation/plan9/blob/ed1a9c21e3297d7497a48053d33683375c75fbb4/sys/src/cmd/sed.c#L108-L117 struct { /* Sed program input control block */ enum PTYPE { /* Either on command line or in file */ P_ARG, P_FILE, } type; union PCTL { /* Pointer to data */ Biobuf *bp; char *curr; }; } prog; And a function taking it as a parameter: https://github.com/plan9foundation/plan9/blob/ed1a9c21e3297d7497a48053d33683375c75fbb4/sys/src/cmd/sed.c#L189 void newfile(enum PTYPE, char *); ------------------------------------------ 9fans: 9fans Permalink: https://9fans.topicbox.com/groups/9fans/T17a31ae1d8c1feb4-Ma36f9b53f43cb9918dbbc10e Delivery options: https://9fans.topicbox.com/groups/9fans/subscription
