[Vala] Fwd: Default Arguments to Functions



Sorry i forgot to send it to the list

---------- Forwarded message ----------
From: CaStarCo <castarco gmail com>
Date: 2010/6/8
Subject: Re: [Vala] Default Arguments to Functions
To: tecywiz121 <tecywiz121 hotmail com>


I don't know very much about Vala.. but I think that the default arguments
in vala functions would be constants.. the reason that lets me to say this
is that the code you want can be done by another way..

and... it's difficult to refer an object that is not initialized yet in the
header of the function

(I supose thath array.length and int.min are correct methods.. i'm a newbye
here)

void do_something(uint8[] array1,
                 uint8[] array2,
                 int len = -1)
{
  if (len < 0) {
    len = int.min(array1.length, array2.length);
  }
  // Do something
}

2010/6/8 tecywiz121 <tecywiz121 hotmail com>

Hi there,

I think I may have found a bug in valac concerning default arguments to
functions.

I'm wondering if what I am doing is wrong, or whether its allowed.

Thanks,
Sam




The following code compiles into incorrect C:

void do_something(uint8[] array1,
                 uint8[] array2,
                 int len = int.min(array1.length, array2.length))
{
   // Do something
}

int main(string[] args)
{
   uint8[] a1 = new uint8[5];
   uint8[] a2 = new uint8[6];

   do_something(a1, a2);

   return 0;
}

I get the following errors:

In function ‘_vala_main’:
error: ‘array1_length1’ undeclared (first use in this function)
error: (Each undeclared identifier is reported only once
error: for each function it appears in.)
error: ‘array2_length1’ undeclared (first use in this function)


_______________________________________________
vala-list mailing list
vala-list gnome org
http://mail.gnome.org/mailman/listinfo/vala-list




-- 
- Per la llibertat del coneixement -
- Per la llibertat de la ment...       -



-- 
- Per la llibertat del coneixement -
- Per la llibertat de la ment...       -


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