return the (value of) assignment

Discussion in 'VHDL' started by valtih1978, Sep 6, 2013.

  1. valtih1978

    valtih1978 Guest

    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.
     
    valtih1978, Sep 6, 2013
    #1
    1. Advertising

  2. valtih1978

    Andy Guest

    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
     
    Andy, Sep 6, 2013
    #2
    1. Advertising

  3. valtih1978

    Tim McBrayer Guest

    On 09/06/13 11:55, valtih1978 wrote:
    >
    > 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,
    --
    Tim McBrayer
    MathWorks
     
    Tim McBrayer, Sep 6, 2013
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Greenhorn
    Replies:
    15
    Views:
    833
    Keith Thompson
    Mar 6, 2005
  2. gsyoon
    Replies:
    4
    Views:
    394
    gsyoon
    Aug 11, 2005
  3. mrstephengross

    Return value of an assignment statement?

    mrstephengross, Feb 21, 2008, in forum: Python
    Replies:
    68
    Views:
    2,141
    Bruno Desthuilliers
    Feb 27, 2008
  4. Sac

    Return value of assignment operator

    Sac, Apr 20, 2009, in forum: C Programming
    Replies:
    19
    Views:
    1,728
    Kenny McCormack
    Apr 23, 2009
  5. Daniel
    Replies:
    4
    Views:
    552
    White Wolf
    Nov 27, 2009
Loading...

Share This Page