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: 9fans
Permalink:
https://9fans.topicbox.com/groups/9fans/T17a31ae1d8c1feb4-M8650c300d3a8f5a680dc1db4
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription