Search code examples
vhdl

No function declarations for operator + error in VHDL


In this piece of code I get this error for the line with +

function func (bv1 : in bit_vector; bv2 : in integer) return bit_vector is

    variable temp : natural := 2**bv2;
    variable result : bit_vector(1 to 32);
  begin
    report "asd" & natural'image(temp);
     result <= bv1 + temp; // this line causes the error
    return result;
  end func;

The error is :

No function declarations for operator +

How can I solve this? I also get a similar error for "=" as well.


Solution

  • It's because you try to add a natural to a bit_vector which does not work because they are of different types. So you'll have to use a converter, e.g. as shown here within one of the functions. The other method is to stick to all the same types, but that isn't always possible.