Search code examples
vala

Does vala have function static variables?


Does Vala have function static variables?

By "function static variable" I mean a variable declared inside a function that keeps its value between invocations, like in the following c example:

#include <stdio.h>

void foo()
{
    int a = 10;
    static int sa = 10;

    a += 5;
    sa += 5;

    printf("a = %d, sa = %d\n", a, sa);
}

Solution

  • No, it doesn't.

    In your example you can either use a global variable or wrap the function in a class and make the variable an attribute of that class.

    The keyword static has a completely different meaning and is only used for class members that are not bound to an instance.