[Vala] error: use of possibly unassigned local variable



Hello list,

I am facing an inconvenient problem.

Suppose I have a C library, that I want to use from vala:

// Always return true
extern bool lib_initialized ();

// data is always set when work returns true
extern bool lib_work (out int data);

int main(string[] args) {
        int the_datum;
        bool has_datum = (lib_initialized () && lib_work (out the_datum));
        if (has_datum) {
                stdout.printf ("Hello, %d!\n", the_datum);
        }
        return 0;
}

If I am to compile this (0.42.5, -C only, not link), I get an error message:

test.vala:11.3-11.44: error: use of possibly unassigned local variable `the_datum'
                stdout.printf ("Hello, %d!\n", the_datum);
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Compilation failed: 1 error(s), 0 warning(s)

The workaround is obvious: initialize the_datum.  However, I like to run my code under valgrind to detect 
when reading
from an uninitialized variable (I make lots of mistakes ^^), and so if there is a bug in lib_work and I 
initialize
the_datum, then I will not be able to notice the problem.

Is it possible to instruct valac that it should not worry?  Or is it possible to change this error to a 
simple warning?

Best regards

Vivien




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]