Announcement

Collapse
No announcement yet.

variable initialization

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • variable initialization

    I have noticed that if I don't explicitly define the value of the variable during the initialization (for example var tmp:=100; ), they are initialized to zero. Is this just a coincidence or is it a rule to which I can rely on in my software? Does this apply to local variables, global variables, arrays, etc?

    This would make a simplification of my code, so in case I have to initialize the variable to zero, I can safely skip the initialization.

  • #2


    yes it can be relied on, all local variables created upon entry to the function are zeroed.
    Also, globals are initialized to zero during initial program load (unless it has an assignment to set it to a specific value during initial program load)

    If you happen to need a static var within a function, just declare as

    var private stickyvar;

    and its value will not change (its actually a private global)

    also, you can initialize a private var with a value, the assignment occurs during initial program loading

    eg
    func myfunc()
    var private value:= 10;
    print(value--);
    endfunc

    each time func is called, it will print 10,9,8,7 etc
    Regards,
    Dave

    Comment

    Working...
    X