Why use #define, implemented by a different processor, when enum, implemented directly by the compiler, does the job?
The Plan 9 C style uses the preprocessor much, much less than contemporary C styles, including ANSI C, because it's simpler to do so. -rob On Wed, Apr 29, 2026 at 8:25 PM 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> Permalink > <https://9fans.topicbox.com/groups/9fans/T17a31ae1d8c1feb4-M8650c300d3a8f5a680dc1db4> > ------------------------------------------ 9fans: 9fans Permalink: https://9fans.topicbox.com/groups/9fans/T17a31ae1d8c1feb4-M4d779991675ab2c3915c7d77 Delivery options: https://9fans.topicbox.com/groups/9fans/subscription
