Treating stand-alone use of function as an implicit VOID cast

Hi all,

I have a question concerning the following three warnings:

** Warning: /home/zs/trunk/FPGA/Library/MemController/tb/MemController_PB.sv(101): (vlog-2240) Treating stand-alone use of function ‘randomize’ as an implicit VOID cast.
** Warning: /home/zs/trunk/FPGA/Library/MemController/tb/MemController_PB.sv(102): (vlog-2240) Treating stand-alone use of function ‘print_Address’ as an implicit VOID cast.
** Warning: /home/zs/trunk/FPGA/Library/MemController/tb/MemController_PB.sv(111): (vlog-2240) Treating stand-alone use of function ‘check_Content’ as an implicit VOID cast.

I don’t know exactly what I did wrong. For example I copied the code example for the randomize-call from the Doulos Golden Reference Guide.

I provide the source code for the class with the other two functions:


package MessageClasses;
    
    class RAM_message_c;
        
        rand bit[7:0] address;
        
        function print_Address;
            $display("RAM Address is %x", address);
        endfunction
        
        function check_Content(input logic[15:0] actualValue);
            logic[7:0] highByte, lowByte;
            logic [15:0] expectedValue;
            lowByte = address;
            highByte = address + 1;
            expectedValue = {highByte, lowByte};
            //$display("Expected value: %x", expectedValue);
            //$display("Actual Value: %x", actualValue);
            assert (expectedValue == actualValue)
                else $error("Expected value and acutal value do not match");
        endfunction
        
        // only even addresses because of 16 bit access
        constraint c_even {
            address % 2 == 0;
        }
        
    endclass
    
    
endpackage

The functions are called in my MainProgram:


    // reading the RAM
    initial begin
        for (int i = 0; i < 10; i++) begin
            RAM_message[i] = new;
        end
        #20_000_000;
        for (int i = 0; i < 10; i++) begin
            RAM_message[i].randomize with { address inside {[0:10]}; };
            RAM_message[i].print_Address;
            @(posedge master_if.clk);
            master_if.RAM_address = RAM_message[i].address;
            master_if.RAM_enable = 'b1;
            // RAM enable must be HIGH for 2 clock cycles => observation was made in Wave Window
            @(posedge master_if.clk);
            @(posedge master_if.clk);
            master_if.RAM_enable = 'b0;
            @(posedge master_if.clk);
            RAM_message[i].check_Content(master_if.RAM_dataOut);
            #5_000;
        end
    end

Thanks in advance for helping to get rid of these warnings!
Kind regards
Sebastian

In reply to sebastian_z:

These functions all have return values which you are ignoring. The randomize() function returns a 1 if successful and a 0 if not successful. You should always check the return value.

Because you omitted a return type in the other two functions, it is assumed to return a 1-bit value. Since you aren’t checking the return values, you are getting the warning. You should declare those functions as ‘function void xxxx()’

In reply to cgales:

Hi cgales,

thank you very much for your answer. OK, this was very obvious, because I’m a C-Developer as well. But because the syntax is a little bit different I was a bit confused. :)

Sorry for the simple question and thanks for your reply!
Kind regards
Sebastian

In reply to sebastian_z:

BTW, if you want to call a function that normally returns a value and ignore it, you can use an explicit cast to void:

void'( my function_with_return_value() )

The reason for the warning is that many people either forget to check the return value of a function that they should have (like randomize), or they forget that functions declared with no return type have an implict 1-bit return type (Verilog had a requirement that all functions have a return type and could only be used in context where an expression was required)