[sv-bc] Questions about default arguments in tasks/functions


Subject: [sv-bc] Questions about default arguments in tasks/functions
From: William Paulsen (paulsen@cadence.com)
Date: Fri Oct 31 2003 - 10:08:13 PST


Hello,

I'd like a few clarifications for Section 10.5.3 of the SV LRM, Default
argument values.
(I've included the LRM section below.)

Thanks,
Bill Paulsen
paulsen@cadence.com

1. The LRM says, "The default_value is any expression that is visible at
the
current scope. It can include any combination of constants or variables
visible
at the scope of both the caller and the subroutine."

Suppose we have this situation:

  A task is declared in a module, and a default value expression for an
argument
  includes a variable that is declared in that module.

  The task is called from another module.

  The argument is omitted in the in call.

This should be an error, because the variable is not visible in the
scope of the
caller.

But suppose the argument in the caller is not omitted - is this still an
error?

(If not an error, then I think the LRM needs additional wording that
says default
value scope checking is not done if the default value is not used in a
subroutine call.)

2. Is this syntax legal for default values:

task mytask2;
  input x = 5; // 5 is the default value
  ...
endtask

3. The LRM says that default values can be specified for each argument.
I think default values should only be specified for input and inout
arguments.
Or can output arguments also have default values? Maybe if the task
never assigns
any value to an output argument, then the output value is the default
value?

---

10.5.3 Default argument values

To handle common cases or allow for unused arguments, SystemVerilog allows a subroutine declaration to specify a default value for each singular argument.

The syntax to declare a default argument in a subroutine is:

subroutine( type argument = default_value );

The default_value is any expression that is visible at the current scope. It can include any combination of constants or variables visible at the scope of both the caller and the subroutine.

When the subroutine is called, arguments with default values can be omitted from the call and the compiler shall insert their corresponding values. Unspecified (or empty) arguments can be used as placeholders for default arguments, allowing the use of non-consecutive default arguments. If an unspecified argument is used for an argument that does not have a default value, a compiler error shall be issued.

task read(int j = 0, int k, int data = 1 ); ... endtask;

This example declares a task read() with two default arguments, j and data. The task can then be called using various default arguments:

read( , 5 ); // is equivalent to read( 0, 5, 1 ); read( 2, 5 ); // is equivalent to read( 2, 5, 1 ); read( , 5, ); // is equivalent to read( 0, 5, 1 ); read( , 5, 7 ); // is equivalent to read( 0, 5, 7 ); read( 1, 5, 2 ); // is equivalent to read( 1, 5, 2 ); read( ); // error; k has no default value

---



This archive was generated by hypermail 2b28 : Fri Oct 31 2003 - 10:11:25 PST