[sv-bc] Function return values

From: Jonathan Bromley <jonathan.bromley_at_.....>
Date: Thu Mar 01 2007 - 01:59:51 PST
SV-BC,

Please accept my apologies if this has already been answered.

In SystemVerilog we have two different ways to return values 
from a function:

<function_name> = <expression>;
return <expression>;

As far as I can see, both methods can coexist in the same 
function.  This yields an ambiguity for static functions.
Does the "return <expression>;" form also, as a side-effect,
update the <function_name> variable?  Consider the following:

module M;  // functions in a module are static by default
  function int F(input bit B, input int I);
    if (B) return I;
  endfunction : F
  initial begin
    $display(F(0,3));   // displays '0'
    $display(F(1,5));   // obviously displays '5'
    $display(F(0,0));   // displays ?????
  end
endmodule : M

My understanding is that the implicit function_name variable
'F' is initialised to 0 like any int, hence the function's
return value in the first call is reliably 0.  But the second
call executes a return statement.  Does this, or does it not,
update F and thereby influence the result of the third call?

Thanks
-- 
Jonathan Bromley, Consultant

DOULOS - Developing Design Know-how
VHDL * Verilog * SystemC * e * Perl * Tcl/Tk * Project Services

Doulos Ltd. Church Hatch, 22 Market Place, Ringwood, Hampshire, BH24 1AW, UK
Tel: +44 (0)1425 471223                   Email: jonathan.bromley@doulos.com
Fax: +44 (0)1425 471573                           Web: http://www.doulos.com

The contents of this message may contain personal views which 
are not the views of Doulos Ltd., unless specifically stated.

-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
Received on Thu Mar 1 02:00:22 2007

This archive was generated by hypermail 2.1.8 : Thu Mar 01 2007 - 02:00:50 PST