Vala: parameter hints - automatic check of the zero value of the parameter value-type out
Problem:
I do have problems using the seemingly nice feature advertised on the Vala / Tutorial site regarding the declaration of output parameters.
Here's a quote from: https://live.gnome.org/Vala/Tutorial#Parameter_Directions
Here is an example of implementation of method_1 ():
void method_1(int a, out int b, ref int c) {
b = a + c;
c = 3; }
By setting a value to out argument "b", Vala will ensure that "b" is nonzero. This way, you can safely pass null as the second argument to method_1 (), if that doesn't interest you.
Looking at the generated C code, it seems clear that unlike the statements above, instead of doing a pre-assignment check, a possible NULL pointer is happily played out.
void method_1 (gint a, gint* b, gint* c) {
*b = a + (*c);
*c = 3;
}
The code I was expecting would take this form instead:
void method_1 (gint a, gint* b, gint* c) {
if (b != NULL)
*b = a + (*c);
*c = 3;
}
The only workaround I've found so far is to drop the entire parameter declaration and go directly with the pointer.
void method_1 (gint a, int* b, ref int c) {
if (b != null)
*b = a + c;
c = 3;
}
For aesthetic reasons, I really liked the idea mentioned in the quote above, so I want to ask the following
QUESTIONS:
-
I misinterpreted the description in the above quote and and the value-type declared parameters cannot be automatically checked for null pointers?
-
Or is it probably a bug in the vala compiler, which is fixed in a later version?
valac --version
returnsVala 0.8.1
, so this is the version I'm using. -
Perhaps there is another chance to perform the parameter type declaration manually with any language element that I am still missing?
source to share