[Vala] (no subject)



I'm using the following code to read command line arguments for two integer
values

------------------

// inside of a class

static int opt_x_part = 0;
static int opt_y_part = 0;

...

public static const OptionEntry[] options = {
    { "xpart", 0, 0, OptionArg.INT, ref opt_x_part,
      "Number of partitions in the x direction", null },
    { "ypart", 0, 0, OptionArg.INT, ref opt_y_part,
      "Number of partitions in the y direction", null },
    { null }
};

...

public int x_part { get; set; default=0; }
public int y_part { get; set; default=0; }
public int n_part { get; set; default=0; }

...

// in the constructor

if (opt_x_part != 0) {
    x_part = opt_x_part;
}
if (opt_y_part != 0) {
    y_part = opt_y_part;
}

n_part = x_part * y_part;

------------------

Later on in the code I want to use n_part but whenever I do I get the
following error during compile:

julia.vala:166.21-166.30: error: Relational operation not supported for
types `int' and `null'
        for (i = 0; i < n_part; i++) {

I assume that it thinks that there's a chance that n_part could be null
because of the ref to opt_x_part/opt_y_part made in the options, but I'm a
little confused as to why they are usable during construction but not
afterwards. What is the way to deal with options correctly to avoid this
error?

Thanks,
Geoff


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