# \[Bro-Commits\] \[git/bro\] rpc: Add support for enum with explicit enumerator values. (0d37c42)

**URL:** <https://community.zeek.org/t/bro-commits-git-bro-rpc-add-support-for-enum-with-explicit-enumerator-values-0d37c42/1757>\
**Category:** Development\
**Tags:** development\
**Created:** [December 10, 2010, 2:48pm UTC](https://community.zeek.org/t/bro-commits-git-bro-rpc-add-support-for-enum-with-explicit-enumerator-values-0d37c42/1757 "2010-12-10T14:48:22Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Seth\_Hall3](https://avatars.discourse-cdn.com/v4/letter/s/d6d6ee/32.png) [@Seth\_Hall3](https://community.zeek.org/u/Seth_Hall3)\
**Post date:** [December 10, 2010, 2:48pm UTC](https://community.zeek.org/t/bro-commits-git-bro-rpc-add-support-for-enum-with-explicit-enumerator-values-0d37c42/1757/1 "2010-12-10T14:48:22Z")

</div>

Quick question, what if this situation is encountered but the enums being autoincremented go up to 11? Will it skip and make the next one 13?

&nbsp;&nbsp;.Seth

---

<div class="post-metadata">

**Author:** ![Vern](https://yyz1.discourse-cdn.com/flex011/user_avatar/community.zeek.org/vern/32/630_2.png) [@Vern](https://community.zeek.org/u/Vern)\
**Post date:** [December 10, 2010, 4:31pm UTC](https://community.zeek.org/t/bro-commits-git-bro-rpc-add-support-for-enum-with-explicit-enumerator-values-0d37c42/1757/2 "2010-12-10T16:31:33Z")

</div>

> \> redef enum foo += {  
> \> BAR\_E, # value will be 12  
> \> BAR\_F = 5, # value will be 5  
> \> BAR\_G, # value will be 6  
> \> };
> 
> Quick question, what if this situation is encountered but the enums being autoincremented go up to 11? Will it skip and make the next one 13?

I'm having a hard time seeing why one would want autoincrement once an  
explicit value is used, and it strikes me as buggy. My view is that either  
\*all\* enums are defined with = X (and it's an error to define two with the  
same value of X), or they're all implicit/autoincrement.

&nbsp;&nbsp;&nbsp;&nbsp;Vern

---

<div class="post-metadata">

**Author:** ![Gregor\_Maier](https://avatars.discourse-cdn.com/v4/letter/g/94ad74/32.png) [@Gregor\_Maier](https://community.zeek.org/u/Gregor_Maier)\
**Post date:** [December 10, 2010, 4:39pm UTC](https://community.zeek.org/t/bro-commits-git-bro-rpc-add-support-for-enum-with-explicit-enumerator-values-0d37c42/1757/3 "2010-12-10T16:39:14Z")

</div>

I think I don't understand the question.  
BAR\_E is autoincremented to 12, because BAR\_D was 11.

If the autoincrement hits a number that has been defined previously, it  
will generate a (parse) error and let you know.

Example:

{ A = 10,  
&nbsp;&nbsp;&nbsp;B = 8,  
&nbsp;&nbsp;&nbsp;C, # implicit 9  
&nbsp;&nbsp;&nbsp;D, # would be implicit 10. ERROR. 10 already exists  
}

A this version would work.  
&nbsp;&nbsp;{ B=8, A=10, C, D }

cu  
Gregor

---

<div class="post-metadata">

**Author:** ![Gregor\_Maier](https://avatars.discourse-cdn.com/v4/letter/g/94ad74/32.png) [@Gregor\_Maier](https://community.zeek.org/u/Gregor_Maier)\
**Post date:** [December 10, 2010, 4:51pm UTC](https://community.zeek.org/t/bro-commits-git-bro-rpc-add-support-for-enum-with-explicit-enumerator-values-0d37c42/1757/4 "2010-12-10T16:51:42Z")

</div>

I guess the only legitimate reason is to provide a seed value for the  
following auto-increment values.  
But I agree, that mixing them freely is a bad idea.

E.g.,  
&nbsp;&nbsp;{  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;A = 100,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;B,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;C,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;D,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;......  
&nbsp;&nbsp;}

Should I change it so that you can't mix auto-increment and explicit  
assignments?

cu  
Gregor

---

<div class="post-metadata">

**Author:** ![Vern](https://yyz1.discourse-cdn.com/flex011/user_avatar/community.zeek.org/vern/32/630_2.png) [@Vern](https://community.zeek.org/u/Vern)\
**Post date:** [December 10, 2010, 4:55pm UTC](https://community.zeek.org/t/bro-commits-git-bro-rpc-add-support-for-enum-with-explicit-enumerator-values-0d37c42/1757/5 "2010-12-10T16:55:48Z")

</div>

> I guess the only legitimate reason is to provide a seed value for the  
> following auto-increment values.

Yeah, though for our purposes that still strikes me as buggy. Seems we'll  
only want an enum to have a particular value if there's a network protocol  
that associates names with values, and we want to mirror it. For those,  
it seems safer to explicitly mirror its values rather than implicitly  
mirroring them. Perhaps we can later add an exception (a single initial  
seed is okay), but for now I think we should go with no mixing of  
auto-increment & explicit.

&nbsp;&nbsp;&nbsp;&nbsp;Vern

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/zeek/original/1X/f09d732bc2cc7c7cc7e35db67cf4e1d5233ce7a7.png) [@system](https://community.zeek.org/u/system)\
**Post date:** [May 6, 2022, 3:39pm UTC](https://community.zeek.org/t/bro-commits-git-bro-rpc-add-support-for-enum-with-explicit-enumerator-values-0d37c42/1757/6 "2022-05-06T15:39:21Z")

</div>

Closed on May 6, 2022, 3:39pm UTC


