我想知道是否有可能以某种方式引用返回类型/值从一个函数返回一个无约束类型的属性。 (做限制,甚至向上传递到所有的功能有个声音告诉我,他们不这样做,并返回类型的约束是由什么决定实际上是在函数内部返回?)例如:可能引用函数返回类型的属性吗?
function f return std_logic_vector is begin
-- how do we access attributes of what we are returning?
-- "return_type" is a placeholder for it here, it would be nice if
-- this information propagated up into the function based on the way
-- the function's result is used when invoked
return (return_type'high - 2 downto return_type'low + 1 => '0', others => '1');
end function;
signal x: std_logic_vector(7 downto 0);
signal y: std_logic_vector(11 downto 0);
[...]
x <= f; -- expect x = "11000001"
y <= f; -- expect y = "110000000001"
我知道这可以通过将所需类型的东西给函数作为参数,像这样被黑身边,但我想,以避免可能的话:
function f(hint: std_logic_vector) return std_logic_vector is
variable retval: std_logic_vector(hint'range);
begin
retval := (hint'high - 2 downto hint'low + 1 => '0', others => '1');
return retval;
end function;
signal x: std_logic_vector(7 downto 0);
signal y: std_logic_vector(11 downto 0);
[...]
x <= f(x); -- x = "11000001"
y <= f(y); -- y = "110000000001"
如果它的事项,我使用的Quartus这需要综合。第二块代码应该可以正常工作(假设我没有犯任何错误),但是我想知道是否有更好的方法来完成这个任务。
请注意,这些是人为的例子,当然有更简单的方法来分配这些值;我在问,一般情况下是否有避免传入额外参数的方法。
有没有人掏槽的LRM和找到相关的东西吗?当你尝试运行第一段代码时,你的模拟器会说什么? – Philippe 2012-01-30 19:17:03