Re: [Vala] functions and null



On Wed, 2011-01-19 at 22:11 +0100, Pavol Klačanský wrote: 
Hi, why this code doesn't work

Item item = null;

parse_content(item);

parse_content(Item item) {
      stderr.printf("argh");
}

reports
** (process:674): CRITICAL **: xml_parser_parse_content: assertion
`item != NULL' failed

This doesn't work because Vala automatically adds an assertion to check
if function parameters are null.  This behavior is the standard for GLib
programs.

If you would like to pass a null value into a function, try (untested):

void parse_content(Item? item) { ... }

The question mark makes the variable 'nullable' meaning that it is
allowed to be null.

I hope that helps,
Sam





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