Which function takes precedence when multiple are visible?

Guest
This seems like it would be a common question, but I can't find the answer.

I just wonder which function takes precedence if there are two functions with the same name (and argument/return types) in different visible packages:

use work.pkga.my_function;
use work.pkgb.my_function;

....

a <= my_function(b); -- am I using pkga or pkgb?
 
On Tuesday, April 2, 2013 9:12:51 PM UTC-4, kevin....@xilinx.com wrote:
This seems like it would be a common question, but I can't find the answer.
I just wonder which function takes precedence if there are two functions
with the same name (and argument/return types) in different visible packages:
use work.pkga.my_function;
use work.pkgb.my_function;
... a <= my_function(b); -- am I using pkga or pkgb?
Neither package will take precedence. When you compile, you will get an error that says something to the effect that there is more than one function that could be used in this case. The language definition does not allow for assumptions to be made (that's a 'good thing' by the way).

If you have to have both packages visible via the 'use' statement than you would have to specify which package you want to use in the functino call like this...

a <= work.pkga.my_function(b);
aa <= work.pkgb.my_function(b);

Kevin Jennings
 
On Tue, 02 Apr 2013 18:12:51 -0700, kevin.neilson wrote:

This seems like it would be a common question, but I can't find the
answer.

I just wonder which function takes precedence if there are two functions
with the same name (and argument/return types) in different visible
packages:

use work.pkga.my_function;
use work.pkgb.my_function;

...

a <= my_function(b); -- am I using pkga or pkgb?
Depends if the functions can be distinguished by argument or return type.
If only one is correct, in context, it will be used.

If both are correct, they are deemed to hide each other and neither is
visible! This leads to slightly confusing error messages "No suitable
function is visible" when actually, at least two of them are...

You can either delete one of the use clauses, or use a qualified name to
call it:
a <= work.pkga.my_function(b);

But it's better than arbitrarily picking one of them.

- Brian
 

Welcome to EDABoard.com

Sponsor

Back
Top