Re: [Vala] Generic type argument



Hi again,

Sorry to spam the list like this, but i just realized what the real problem was.

I've digged a bit further on my problem. Compiling the vala code to C
code, showed a temporary variable which was a float. Changing this
variable to a double fixes the problem of the 'random' value. I've
attached a minimal sample vala program, and diff to change the
resulting c code. (all with vala 0.7.5)

Compiling the piece of sample code with 5.0 instead of 5.0f works
correctly. So the float variable was correct in the c code, as i
wanted to store 0.5f which is a float. However, the target variable
was a double, so valac should cast it to a double. It didn't and just
tried to copy a float into a double, which obviously went wrong.

It can be argued that the mistake's on my side, which is true.
However, silently ignoring the issue like vala does now is wrong too,
imho. It should either give a compile error or just cast it to a
double.

Kind regards,
Thomas

This still leaves me wondering why i need to box a double to use it as
a generic type, while an int can be used just like that.

Kind regards,
Thomas Meire

On Fri, Aug 7, 2009 at 8:53 PM, Thomas Meire<blackskad gmail com> wrote:
Hi all,

I tried to store a double in a Gee.Map for some algorithms I'm
writing, but the program failed to compile (with valac errors). After
reading a bit in the tutorial[1] and the reference draft[2], I decided
to try the example in the reference manual[3]. However, the program
failed to compile with the same error I had in my algorithms:

"error: `double' is not a supported generic type argument, use `?' to
box value types"

So I changed that line a bit to look like:

var t = new Two < int, double? > ();

With that line, it compiles (with some warnings), but the output is
not correct. It outputs some 'random' value instead of 5.
So what can i do to make the program compile and make it do what it's
supposed to do?

Thanks a lot,
Thomas

[1] http://live.gnome.org/Vala/Tutorial
[2] http://www.vala-project.org/doc/vala-draft/
[3] http://www.vala-project.org/doc/vala-draft/generics.html#genericsexamples





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