Does specman have static variables?

I have the following code in specman which I inherited:

some_method() is {
    var a: bool;

    if (!a) {
        a = some_other_method();
    };
};

      

I understand that every time it some_method()

is called, a

generated anew, and there is no point in checking the value a

before assigning it. However, I may have missed something. For example, if it a

is static, then this code makes sense, which brings me to my question:

Is there a way for a variable to be static in specman?

+1


a source to share


2 answers


there are no static variables as in C. A variable in a method has a default value ( False

in this case) if it is not initialized, so you should be right if (!a)

always should be True

.

It would be different if it a

was a member of a struct, then, as in other OO languages, it would store the value over multiple method calls, and the check would make sense:

struct some_struct_s {
    a : bool;
    some_method() is {
        if (!a) {
            a = some_other_method();
        };
    };
};

      

You can also check things like this in the interactive prompt:

Specman> var a : bool;
Specman> print a
  a = FALSE

      



There online help is also good, for example try:

Specman> help variable

      

and select the entry (by number) sn_eref: variables : declaring

. There you will find all the information you need for your question.

Cheers, Daniel

+3


a source


Static structure elements (events, fields, methods) were added to the language in Specman v15.2. Static field cannot be generated, physical (%), or used on subtypes.

struct some_struct_s {
    a : bool;
    some_method() is {
        if (!a) {
            a = some_other_method();
        };
    };
};

-- Change field 'a' for all instances
on xxx { some_struct_s::a = TRUE; };

      



Here are some comments from the teampecman blog: Static members in e

0


a source







All Articles