[bind10-dev] Enums as array indices and manual vs. auto-numbering

Yoshitaka Aharen aharen at jprs.co.jp
Thu Aug 25 12:06:21 UTC 2011


Hello,

+1 to the opinion. If there's no rationale behind numbering enums
manually, I prefer to assign numbers automatically. I also believe that
it is safer.

Google Style Guide shows an example which omits assigning numbers:
http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml?showone=Enumerator_Names#Enumerator_Names

Best Regards,

On Thu, 25 Aug 2011 13:50:39 +0200
"Michal 'vorner' Vaner" <michal.vaner at nic.cz> wrote:

> Hello
> 
> AFAIK our code guideline suggests that whenever we write an enum, we should
> manually assign numbers to it:
> 
> enum X {
>   A = 0,
>   B = 1
> };
> 
> However, we sometime use an enum as constants for named indices of array:
> 
> enum Indices {
>   FOO = 0,
>   BAR = 1,
>   BAZ = 2,
>   COUNT = 3
> }
> int array[COUNT];
> 
> array[FOO] = 42;
> 
> 
> I don't know the rationale behind numbering them manually, but in this case I
> think it is error prone, because human will just overlook it and assign bad
> number. If we rely on the compiler auto-assigning, C and C++ guarantees
> numbering them from zero in by-one increasing way (the rules are more
> complicated, but in case it's left completely on the compiler, this simple one
> follows from it). In this case I believe the auto-assigning is actually safer.
> 
> What reason do I overlook? Or should we revisit the code guidelines?
> 
> Thank you
> 
> With regards
> 
> -- 
> Never underestimate the bandwidth of a station wagon full of HDDs.
> 
> Michal 'vorner' Vaner

-- 
Yoshitaka Aharen <aharen at jprs.co.jp>
Japan Registry Services Co., Ltd.





More information about the bind10-dev mailing list