return the (value of) assignment

V

valtih1978

Here is a funny code that I have Modelsimed

process
function COMPUTE return boolean is
constant STR: string := "abc";
begin
-- Error1: Target of signal assignment
-- is not a signal.
--STR <= STR;

-- Error2: Constant "STR" cannot be target of
-- variable assignment statement.
--STR := STR;

-- Return assignment is OK!
return STR <= "xyz";
end function;


-- Error3: Type error resolving function call
-- "COMPUTE" as type std.STANDARD.STRING.
--constant STR: string := COMPUTE;

constant B2:boolean := COMPUTE;
begin
report "Computed b2 = " & boolean'image(B2);
wait;
end process;

I am getting "Computed b2 = true" in the output despite I do not see
anywhere how the assignment in the end of COMPUTE function evaluates to
a boolean. A stand-alone assignment would violate checks marked with
error1 and error2.
 
A

Andy

There is no assignment statement in your (uncommented) example code.

The statement here is "return <expression>" and the expression returns true if STR is less than or equal to "xyz".

VHDL defines the <= operator for l,r operands of the same type. The evaluation is based on the size of the arrays.

VHDL operators can be overloaded, to implement more complex operations, such as is done in numeric_std for

function "<=" (unsigned, unsigned) return boolean;

Which evaluates the contents of the arrays to determine the result.

A less ambiguous example would have been:

return STR := "xyz";

Since ":=" is not also a vhdl operator.

Andy
 
T

Tim McBrayer

Here is a funny code that I have Modelsimed

process
function COMPUTE return boolean is
constant STR: string := "abc";
begin
-- Error1: Target of signal assignment
-- is not a signal.
--STR <= STR;

-- Error2: Constant "STR" cannot be target of
-- variable assignment statement.
--STR := STR;

-- Return assignment is OK!
return STR <= "xyz";
end function;


-- Error3: Type error resolving function call
-- "COMPUTE" as type std.STANDARD.STRING.
--constant STR: string := COMPUTE;

constant B2:boolean := COMPUTE;
begin
report "Computed b2 = " & boolean'image(B2);
wait;
end process;

I am getting "Computed b2 = true" in the output despite I do not see anywhere how the
assignment in the end of COMPUTE function evaluates to a boolean. A stand-alone assignment
would violate checks marked with error1 and error2.

In your example, '<=' is getting interpreted as 'less than or equal to', not 'signal
assignment' here. It is true that "abc" <= "xyz", thus the returned boolean value.

Regards,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top