# declaration error: &default function type clash

**URL:** <https://community.zeek.org/t/declaration-error-default-function-type-clash/4155>\
**Category:** Development\
**Tags:** development\
**Created:** [May 12, 2016, 8:44am UTC](https://community.zeek.org/t/declaration-error-default-function-type-clash/4155 "2016-05-12T08:44:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aashish\_Sharma1](https://avatars.discourse-cdn.com/v4/letter/a/a88e57/32.png) [@Aashish\_Sharma1](https://community.zeek.org/u/Aashish_Sharma1)\
**Post date:** [May 12, 2016, 8:44am UTC](https://community.zeek.org/t/declaration-error-default-function-type-clash/4155/1 "2016-05-12T08:44:58Z")

</div>

So I am trying to convert tables into using opaque of cardinality since thats more memory efficient (or counting bloomfilters for that matter):

works: if table (0) converted to (1)  
errors: if table (2) converted to (3)

Details: I am trying the following, original table (0) converted to (1):

(0) global likely\_scanner: table[addr,port] of set[addr] &read\_expire=1 day &synchronized ;

(1) global c\_likely\_scanner: table[addr] of opaque of cardinality  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&default = function(n: any): opaque of cardinality { return hll\_cardinality\_init(0.1, 0.95); }  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&read\_expire=1 day ;

ERRORS:

(2) global likely\_scanner: table[addr,port] of set[addr] &read\_expire=1 day &synchronized ;

Converted table:

(3) global c\_likely\_scanner: table[addr,port] of opaque of cardinality  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&default = function(n: any): opaque of cardinality { return hll\_cardinality\_init(0.1, 0.95); }  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&read\_expire=1 day ;

I get this error:

check-knock.bro, line 58: &default function type clash (&default=anonymous-function{ return (hll\_cardinality\_init(0.1, 0.95))})

Question:

how do I declare (3) so that I can avoid the "&default function type clash" error above.

I am not sure what am I doing wrong in the declaration. Any thoughts/advice how to get past this issue ?

Thanks,  
Aashish

---

<div class="post-metadata">

**Author:** ![Jan](https://avatars.discourse-cdn.com/v4/letter/j/ce7236/32.png) [@Jan](https://community.zeek.org/u/Jan)\
**Post date:** [May 12, 2016, 2:36pm UTC](https://community.zeek.org/t/declaration-error-default-function-type-clash/4155/2 "2016-05-12T14:36:36Z")

</div>

> how do I declare (3) so that I can avoid the "&default function type clash" error above.

I guess the function for initialization receives the index that should  
be initialized. In this case the index consists of two values. I tried  
the following and Bro did not complain:

global c\_likely\_scanner: table[addr,port] of opaque of cardinality  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&default = function(a: addr, p: port): opaque of cardinality {  
return hll\_cardinality\_init(0.1, 0.95); }  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&read\_expire=1 day;

Hope that works for you!

Regards,  
Jan

---

<div class="post-metadata">

**Author:** ![Aashish\_Sharma1](https://avatars.discourse-cdn.com/v4/letter/a/a88e57/32.png) [@Aashish\_Sharma1](https://community.zeek.org/u/Aashish_Sharma1)\
**Post date:** [May 12, 2016, 5:12pm UTC](https://community.zeek.org/t/declaration-error-default-function-type-clash/4155/3 "2016-05-12T17:12:41Z")

</div>

Jan,

> I guess the function for initialization receives the index that should  
> be initialized.

Thank you. This works!

For future reference:

I also needed to convert the following table to use opaque of cardinality for this table grows reasonably big:

global distinct\_backscatter\_peers: table[addr] of table[port] of set[addr] &read\_expire=1 day;

Here is how I did this one:

type bs: table[port] of opaque of cardinality &default=function(p:port): opaque of cardinality {return hll\_cardinality\_init(0.1, 0.95); };  
global c\_distinct\_backscatter\_peers: table[addr] of bs &read\_expire=1 day ;

and to access:

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ( orig !in c\_distinct\_backscatter\_peers)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c\_distinct\_backscatter\_peers[orig] = table() ;

&nbsp;&nbsp;if (s\_port !in c\_distinct\_backscatter\_peers[orig])  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;local cp: opaque of cardinality = hll\_cardinality\_init(0.1, 0.95);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c\_distinct\_backscatter\_peers[orig][s\_port]=cp ;  
&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hll\_cardinality\_add(c\_distinct\_backscatter\_peers[orig][s\_port], resp);

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;local d\_val = double\_to\_count(hll\_cardinality\_estimate(c\_distinct\_backscatter\_peers[orig][s\_port]));

&nbsp;&nbsp;### use d\_val here ....

Now may be there is a better more elegant way to do this, but above seems to work for me.

Again, thanks Jan!!

Aashish

---

<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:43pm UTC](https://community.zeek.org/t/declaration-error-default-function-type-clash/4155/4 "2022-05-06T15:43:41Z")

</div>


