tags:

views:

88

answers:

1

I have the following code in specman that I inherited:

some_method() is {
    var a: bool;

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

My understanding is that each time some_method() is called, a is generated anew, and there's no sense in checking a's value before it's assigned. However, it may be that I'm missing something here. For instance, if a is static then this code makes sense, which brings me to my question:

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

+2  A: 

Hi Nathan,

there are no static variables as in C. A variable in a method has its default value (False in this case) if not initialized, so you should be right if (!a) should always be True.

Things would be different if a was a struct member, then like in other OO languages it would retain there value over several method calls and the check would make more sense:

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

You can check stuff like this also on the interactive prompt:

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

There the interactive help is also nice, for example try:

Specman> help variable

and select the entry (by number) sn_eref: variables : declaring. There you will find all relevant information for your question.

Cheers, Daniel

danielpoe