Re: some strange behavior
//o schrieb: Writing a small opengl text printer (vertex based) I have found that the next lines are illegal to dmd (2.031): invariant float[][][] CHARS =[ [//A [0,0], [1/2f,2], [1,0], [3/4f,1], [1/4f,1] ] ]; dmd complains (compiling with dmd -c bug.d): bug.d(9): Error: cannot implicitly convert expression ([0.5F,2F]) of type float[2u] to int[] bug.d(9): Error: cannot implicitly convert expression ([0.75F,1F]) of type float[2u] to int[] bug.d(9): Error: cannot implicitly convert expression ([0.25F,1F]) of type float[2u] to int[] is this a bug? thanks. -- if this mesage is repeated there's a problem with my browser The type of the first element makes the type of the array literal. 0 is of type int, try 0f. invariant float[][][] CHARS =[ [//A [0f,0], [1/2f,2], [1,0], [3/4f,1], [1/4f,1] ] ];
calling function templates
I noticed that I don't always have to use the bang notation for function templates. I played around with that a little, but got an error when I used a static array. I think it's because of a casting problem or wrong type inference... I don't imagine it's a bug. Just not possible. module test; import std.range; void putNumbers(Range, T)(Range r, T start, T incr) { T i = start; while (!r.empty) { r.put(i); // line 8 i += incr; } } void main() { int[] arr = new int[20]; putNumbers!(int[])(arr, 0, 3); // dyn array, bang notation int[] arr2 = new int[20]; putNumbers(arr2, 0, 3); // dyn array, regular notation int[20] arr3; putNumbers!(int[])(arr3, 0, 3); // stat array, bang notation int[20] arr4; putNumbers(arr4, 0, 3); // ERROR, stat array, regular notation } test.d(8): Error: cast(int[])r is not an lvalue test.d(25): Error: template instance test.putNumbers!(int[20u],int) error instantiating
Re: Shared Object with DMD v2.031
teo 写道: I have difficulties creating a Shared Object (.so) with D. Is it possible? Can I use classes defined in the library from the executable? All the steps have been done successfully on FreeBSD 7.2 with DMD v1.046 + gcc v 4.2.1 20070719. The running of this line writefln(testMe: %d, testMe()); is OK. However, when running this line writefln(Test class: %d, (new Test(3)).get()); I got core dumped. The dumped file is so huge nearly 1G. Maybe I should report this bug?
Re: Shared Object with DMD v2.031
On Sun, 09 Aug 2009 17:22:14 +0800, zxp wrote: teo 写道: I have difficulties creating a Shared Object (.so) with D. Is it possible? Can I use classes defined in the library from the executable? All the steps have been done successfully on FreeBSD 7.2 with DMD v1.046 + gcc v 4.2.1 20070719. The running of this line writefln(testMe: %d, testMe()); is OK. However, when running this line writefln(Test class: %d, (new Test(3)).get()); I got core dumped. The dumped file is so huge nearly 1G. Maybe I should report this bug? Have a look at the bug Sergey reported: http://d.puremagic.com/issues/show_bug.cgi?id=3226 Maybe this is the cause.
Re: Linking Tango + QtD under Ubuntu (with Rebuild)
Michael Mittner wrote: I'm trying to evaluate QtD. First step is to link something against Tango and Qt, but unfortunately I can't get it to work: rebuild main.d -debug -full -oqobj/ -I~/coding -llqtdcore -llqtdgui - llQtCore -llQtGui I have Tango installed via apt-get (and the Tango repository), as well as libqt4-dev and all its dependencies, but still the linker can resolve almost nothing. When I remove the QtD imports and simply link against Tango (with a test Stdout), it links and runs. Has anybody run into some similar problem? I've never been good at this linking business and I'm out of ideas :( so help would be much appreciated. Regards, Mike Hello Mike. This works well for me: rebuild -oq.build main.d -L-lqtdgui -L-lqtdcore -L-lQtCore -L-lQtGui /Brix
Re: calling function templates
And a more general note Jos van Uden: don't use D2, it's unfinished, things don't work yet. Use a stable version of D1, like 1.042. Bye, bearophile
Re: calling function templates
bearophile wrote: And a more general note Jos van Uden: don't use D2, it's unfinished, things don't work yet. Use a stable version of D1, like 1.042. Bye, bearophile I'm not using the language. Just trying to learn it. Most code examples I see, require D2. Jos
Re: calling function templates
Jos van Uden: I'm not using the language. Just trying to learn it. To learn a programming language you have to use it some. Most code examples I see, require D2. Then don't look at them, and do your own experiments, etc. Bye, bearophile
Re: calling function templates
On Sun, Aug 9, 2009 at 9:30 AM, bearophilebearophileh...@lycos.com wrote: Jos van Uden: I'm not using the language. Just trying to learn it. To learn a programming language you have to use it some. Most code examples I see, require D2. Then don't look at them, and do your own experiments, etc. Aw come on. I'd learn D2 if I were just getting into D now. It's where all the action is heading these days. If you don't like dealing with the bleeding edge, then yeh, D1 is better for now. But there are reasons why a person might prefer to learn either. --bb
Re: calling function templates
Jos van Uden wrote: I noticed that I don't always have to use the bang notation for function templates. I played around with that a little, but got an error when I used a static array. I think it's because of a casting problem or wrong type inference... I don't imagine it's a bug. Just not possible. ... int[20] arr4; putNumbers(arr4, 0, 3); // ERROR, stat array, regular notation } test.d(8): Error: cast(int[])r is not an lvalue test.d(25): Error: template instance test.putNumbers!(int[20u],int) error instantiating You're instantiating the template as putNumbers!(int[20u],int) because arr4 is of type int[20u]. This means Range is int[20u]. Here's the code for put: void put(T, E)(ref T[] a, E e) { assert(a.length); a[0] = e; a = a[1 .. $]; } r.put(i) is rewritten by the compiler as put(r, i)... except that put wants an int[], not an int[20u]. So it implicitly casts it to the correct type, giving put(cast(int[])r, i). But put ALSO expects its first argument to be passed by reference, and you cannot pass the result of a cast by-reference. (There are a LOT of things you can't pass by reference; it's a constant thorn in my side, and many others' sides.) The problem here is that put is fundamentally incompatible with fixed-size arrays. The solution is to change line 25 to read: auto arr4_temp = arr4[]; putNumbers(arr4_temp, 0, 3);