1

How do I pass an empty integer_vector with length equals zero? (= NULL array)

Background:

Inside a Testbench I´d like to use a procedure for different types of transactions. Something like this:

entity foo is
end entity foo;

architecture bar of foo is
  procedure Transaction (
        constant RX_BYTES     : integer_vector
        ) is
    begin
        report "RX_BYTES'length = " & to_string(RX_BYTES'length);
    end procedure;
begin

  Transaction(RX_BYTES => ""); -- it´s about this line

end architecture bar;

I have something like this in mind, but that doesn´t work:

Transaction(RX_BYTES => "");

ModelSim error:

** Error: C:/Users/sbuhrow/Desktop/NULL_Vector.vhd(13): (vcom-1600) No feasible entries for subprogram "Transaction".
7
  • 2
    Would you mind to provide a minimal reproducible example, please? Commented Jan 5, 2024 at 10:56
  • What's here not repoducable and minimal? Commented Jan 5, 2024 at 15:20
  • 1
    @am9417 Did you visit the linked page? We need to copy and paste the source to reproduce. Currently this is not possible. Commented Jan 5, 2024 at 16:00
  • @thebusybee As the question is about something the OP don't know how to do they cannot really provide an interesting MCVE. MCVE are nice when people want help with unexpected results, but here there is no result at all because they don't know how to code what they need. Commented Jan 5, 2024 at 16:57
  • @RenaudPacalet As your answer proves, there is a minimal reproducible example. With the form the OP chose, it will produce an error. But that is fine. It gives us a starting point. Commented Jan 5, 2024 at 19:01

1 Answer 1

5

Simply use an empty range:

Transaction(RX_BYTES => (1 to 0 => 0), ...);

Demo:

$ cat foo.vhd
entity foo is
end entity foo;

architecture bar of foo is
  procedure p(constant c: integer_vector) is
  begin
    report "c'length = " & to_string(c'length);
  end procedure p;
begin
  p(c => (0 downto 1 => 0));
end architecture bar;

$ ghdl -a --std=08 foo.vhd
$ ghdl -r --std=08 foo
foo.vhd:7:5:@0ms:(report note): c'length = 0

Note: if you will use such an empty integer vector frequently you could also declare a constant:

constant empty_iv: integer_vector := (1 to 0 => 0);

And use it everywhere you need it.

Sign up to request clarification or add additional context in comments.

1 Comment

That works :-) I needed some time to understand that the key is the intentional "wrong" use of indices: e.g. (0 downto 1) has the lower number on the left side which results in the wanted null range vector.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.