Search code examples
syntaxspecmanecolon-equals

Specman e: When colon equal sign ":=" should be used?


I saw in some Specman e code example the use of := (colon-equal sign), e.g.:

var regs_type := rf_manager.get_exact_subtype_of_instance(graphics_regs);

When and why should we use := ? Thank you for your help.


Solution

  • The := means declare a variable of the type the expression on the right returns and assign it to that value. Basically, in your example, the function get_exact_subtype_of_instance(...) returns a value of type rf_struct. The regs_type variable will be declared to that type.

    This code is equivalent to (but shorter than):

    var regs_type : rf_struct = rf_manager.get_exact_subtype_of_instance(graphics_regs);
    

    This syntax is particularly helpful when casting:

     var foo := some_struct.as_a(FOO some_struct_type);