# enums in modules

**URL:** <https://community.zeek.org/t/enums-in-modules/1801>\
**Category:** Development\
**Tags:** development\
**Created:** [January 20, 2011, 9:50pm UTC](https://community.zeek.org/t/enums-in-modules/1801 "2011-01-20T21:50:47Z")\
**Posts on this page:** 10\
**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:** [January 20, 2011, 9:50pm UTC](https://community.zeek.org/t/enums-in-modules/1801/1 "2011-01-20T21:50:47Z")

</div>

How would I refer to an enum type as type for an argument in a BiF or function? I have an enum named Logging::ID, and I want it to be the first argument in this BiF...

function logging\_log%(id: Logging::ID, rec: any%): bool

That obviously doesn't parse though, are there any workarounds?

&nbsp;&nbsp;.Seth

---

<div class="post-metadata">

**Author:** ![robin](https://yyz1.discourse-cdn.com/flex011/user_avatar/community.zeek.org/robin/32/599_2.png) [@robin](https://community.zeek.org/u/robin)\
**Post date:** [January 22, 2011, 10:18pm UTC](https://community.zeek.org/t/enums-in-modules/1801/2 "2011-01-22T22:18:54Z")

</div>

Would be nice if that worked. Seems like something we should fix  
eventually.

I'm actually not quite sure to which degree enums are supported by  
bifcl right now. Two things you could try: (1) do they work if they  
don't have namespace?; and (2) does it work to say just ":enum"  
(probably not).

The alternative would be to use "any" and check for the type's  
correctness dynamically inside the function body until we have fixed  
this.

(The other work-around is using strings, as I think you said you are  
alrady doing now) .

Robin

---

<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:** [January 23, 2011, 6:21am UTC](https://community.zeek.org/t/enums-in-modules/1801/3 "2011-01-23T06:21:51Z")

</div>

> I'm actually not quite sure to which degree enums are supported by  
> bifcl right now. Two things you could try: (1) do they work if they  
> don't have namespace?;

I think that does work, it's the namespacing that messes things up because the Bro and C syntaxes don't mesh. Maybe bifcl could munge namespaces from Logging::ID to \_Logging\_\_ID or something to provide the transition?

> and (2) does it work to say just ":enum"  
> (probably not).

I can't imagine that it would work. I'll give it a try though.

> The alternative would be to use "any" and check for the type's  
> correctness dynamically inside the function body until we have fixed  
> this.

Good point, I may go that way once I have the other kinks worked out.

Thanks,  
.Seth

---

<div class="post-metadata">

**Author:** ![robin](https://yyz1.discourse-cdn.com/flex011/user_avatar/community.zeek.org/robin/32/599_2.png) [@robin](https://community.zeek.org/u/robin)\
**Post date:** [January 24, 2011, 4:31pm UTC](https://community.zeek.org/t/enums-in-modules/1801/4 "2011-01-24T16:31:33Z")

</div>

I'd need to look closer at bifcl. Can you file a ticket with a small  
example demonstrating the problem? Thanks,

Robin

---

<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:** [January 24, 2011, 7:46pm UTC](https://community.zeek.org/t/enums-in-modules/1801/5 "2011-01-24T19:46:12Z")

</div>

bifcl supports enums (it just casts them as a "neutral" Val\*, same as  
for record types). So it would just be a matter of telling bifcl to  
accept the Namespace::Type name syntax. That should be it.

The C part doesn't really care about the type. It's all a "netural"  
Val\*. The type is only used for the policy file and type checking.

EnumType and EnumVal should make accessing the enum's value relatively  
easy. I'm using that in my re-working of the NFS analyzer. Let me know  
if you want details.

cu  
Gregor

---

<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:** [January 24, 2011, 7:50pm UTC](https://community.zeek.org/t/enums-in-modules/1801/6 "2011-01-24T19:50:07Z")

</div>

After taking a deeper look into this, I realized that I may be misunderstanding how enums are supposed to be used. Does it make sense that you'd provide an enum name as a type to get static type checking? Like this...

\<code example\>  
type TEST\_ENUM: enum { test\_one, test\_two, test\_three };

function blah(b: TEST\_ENUM)  
&nbsp;&nbsp;{  
&nbsp;&nbsp;print "did it work?";  
&nbsp;&nbsp;}

event bro\_init()  
&nbsp;&nbsp;{  
&nbsp;&nbsp;local a = test\_two;  
&nbsp;&nbsp;print blah(a);  
&nbsp;&nbsp;}  
\</code example\>

I get this error from that code..

[seth@Blake build (master)]$ ./src/bro test.bro  
./test.bro, line 11 (print blah(a)): error, value of type void illegal

Before I send my example for namespaced enums, I think I need to get more of the base usage of enums clarified. Are there any examples that you know of where enums are used as parameter values like this?

&nbsp;&nbsp;.Seth

---

<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:** [January 24, 2011, 7:56pm UTC](https://community.zeek.org/t/enums-in-modules/1801/7 "2011-01-24T19:56:12Z")

</div>

blah() doesn't return anything, so you can't print it....

cu  
Gregor

---

<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:** [January 24, 2011, 8:01pm UTC](https://community.zeek.org/t/enums-in-modules/1801/8 "2011-01-24T20:01:02Z")

</div>

Haha, whoops. Ok, that throws my whole thought out the window. Thanks for your comments, I'll look at things a bit more.

&nbsp;&nbsp;.Seth

---

<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:** [January 24, 2011, 8:36pm UTC](https://community.zeek.org/t/enums-in-modules/1801/9 "2011-01-24T20:36:39Z")

</div>

I don't think that enums are used extensively between C and policy  
scripts. AFAIK, my NFS analyzer is one of the first that passes enums as  
event arguments.

cu  
gregor

---

<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/enums-in-modules/1801/10 "2022-05-06T15:39:25Z")

</div>


