I think checking if (the_datum != null) should do

Em sáb, 16 de fev de 2019 10:00, <vala-list-requ...@gnome.org escreveu:

> Send vala-list mailing list submissions to
>         vala-list@gnome.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
>         https://mail.gnome.org/mailman/listinfo/vala-list
> or, via email, send a message with subject or body 'help' to
>         vala-list-requ...@gnome.org
>
> You can reach the person managing the list at
>         vala-list-ow...@gnome.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of vala-list digest..."
>
>
> Today's Topics:
>
>    1. error: use of possibly unassigned local variable (Vivien Kraus)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Fri, 15 Feb 2019 21:28:45 +0100
> From: Vivien Kraus <viv...@planete-kraus.eu>
> To: vala-list@gnome.org
> Subject: [Vala] error: use of possibly unassigned local variable
> Message-ID:
>         <40a1141df0d06b59ed0f87f3a6cafac285f45b4a.ca...@planete-kraus.eu>
> Content-Type: text/plain; charset="UTF-8"
>
> 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
>
>
>
>
> ------------------------------
>
> Subject: Digest Footer
>
> _______________________________________________
> vala-list mailing list
> vala-list@gnome.org
> https://mail.gnome.org/mailman/listinfo/vala-list
>
>
> ------------------------------
>
> End of vala-list Digest, Vol 133, Issue 6
> *****************************************
>
_______________________________________________
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list

Reply via email to