1

I'm sure it can be done, but getting stuck in the type naming.

VHDL function = function function_name (parameters : type) return type is

    *parameters* = a label for an input parameter to the function.
    *type* = the type of the parameter, like std_logic, std_logic_vector, string or other.   

VHDL array = type type_name is array (range) of element_type

    *range* = The range of elements the array is going to occupy.
    *element_type* = The type of each element in the array. "type" is like the type discussed for the function.

An array defines its own type.

How to get it assigned as type of a parameter to the function?

When an array is used in the function, how to assign it as return value of the function?

Can somebody provide an or some examples?

Thanks in advance.

1
  • 1
    As far as I remember, std_logic_vector is an array. Commented Dec 7, 2016 at 8:55

1 Answer 1

2

One of the great things about VHDL is that it is a very well thought out and consistent language. If it makes sense to do something, you generally can; if you can do something in one place, you can generally do it in another. All the inputs to a function have to have a type; the return value from a function has to have a type. As you say, an array is a type. Therefore, the inputs to and return value from a function can be arrays. Here is an example:

  type MY_ARRAY is array (0 to 9) of integer;

  function MY_ARRAY_FUNC (I : MY_ARRAY) return MY_ARRAY is
  begin
    return (9,8,7,6,5,4,3,2,1,0);
  end function;

https://www.edaplayground.com/x/njv

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

1 Comment

is there a way to return an array from a function without defining the type beforehand, I have to support a function in a package and the array size is determined by generics so that I don't have to put the functions in that specific module... Other libraries need access to this function, so I am trying to figure out how to return an array based on parameters I pass to the function

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.