Re: "not an lvalue"
On 5/1/2011 3:53 PM, Dmitry Olshansky wrote: Ehm.. Well, first things first: you shouldn't use classes for lightweight & plain data things like vectors. There are structs for that. In general, structs are value-like objects living on the stack while classes are reference-like objects living on the heap. Your current code is going to allocate on GC heap new vector in every GetColumn and I suspect also when adding two vectors. Yes, I will change that, thank you. Btw, I'd like to mention that in addition to being allocated on the heap, classes also be 2 pointers larger because of the hidden __vptr and __monitor.
Re: "not an lvalue"
Yes, you were right: Vector3 { // ... /// Binary operator for operator + and - public Vector3 opBinary(string op) (const ref Vector3 rhs) const if (op == "+" || op == "-") { mixin("return new Vector3(x" ~ op ~ "rhs.x, y" ~ op ~ "rhs.y, z" ~ op ~ "rhs.z);"); } // ... } I removed ref and it worked. I'm a bit confused by this, I'll go read up on the ref keyword.
"not an lvalue"
Hi, I've been away from D for a while, but now I'm back and I'm stuck with an compile time error. I've got a Matrix33 class and a Vector3 class, but something is wrong with the way I return my Vector3 in my matrix class: If I do this I get an error: Matrix33 mtest = new Matrix33(); mtest.SetIdentity(); Vector3 test1 = new Vector3(0, 0, 0); Vector3 test2 = test + mtest.GetColumn(2); I get the error "Error: mtest.GetColumn(x) is not an lvalue" But the following works: Matrix33 mtest = new Matrix33(); mtest.SetIdentity(); Vector3 test1 = new Vector3(0, 0, 0); Vector3 temp = mtest.GetColumn(2); Vector3 test2 = test + temp; // GetColumn method Matrix33 { // ... /// Get a matrix column, horizontal line Vector3 GetColumn(uint index) { assert(!(index > 2), "index is too high"); return new Vector3(cell[index * 3], cell[index * 3 + 1], cell[index * 3 + 2]); } // ... } My questions: What changes do I have to make to make the first example compile?
Re: import from subdir
On 12/23/2010 1:38 PM, spir wrote: Is there a way to import util& data from test? I think this should work: util.d first line: module util; data.d first line module data.data; test.d first lines module test.test; import util; import data.data; Disclaimer: I don't know if directory names and file names may overlap, maybe you should rename them.
d programming environment tutorial.
Hello, I've known D for about two weeks right now, and I kind of like it, a lot, but, I had a lot of trouble figuring out how to set up a programming environment. I mean, there were a few choices but some were abandoned, some things were only for D1(tango??) and others were so bug ridden that I could not really use without wanting to punch a hole in a wall every 10 minutes :P. Anyway, I did manage to set up a satisfactory programming environment with programmers notepad. I know I'm not the best programmer here by a long shot, but I still like to support D so I made a video tutorial on how to set it up: http://www.youtube.com/watch?v=OD8dMclELgI I've set up a basic SDL project with a little help of Derelict, I think I'll be making more tutorials in the future, It'll be about simple things like, programming a particle system in d or maybe a simple ray tracer. Don't have anything planned out yet, But whatever, I can think ahead later! Hope you find my video useful.
Re: rdmd bug?
So, should I report this as a bug? What am i saying!? of course I should. It annoyed the hell outta me >_< *goes to report*
Re: rdmd bug?
Add -Ifullpath_to_projectfolder\src. It's the way it works IMHO, if you import something it must be relative to search path or to current dir. There may be a better way (replace current dir with the dir where source is, but it will take away control), but this works. There is a bug though, I can't make it work with -Irelative_path_to_src. Looks like .deps contain paths relative to where rdmd was ran, while dmd interprets them as paths relative to where .deps file is. I've tried -I"path to src" but this doesn't work either, but I've found a workaround. I start a batch file that goes to the correct directory and then executes rdmd with the argument(the absolute path) I pass to the batch file, this works :D Thanks for the help! So, should I report this as a bug?
rdmd bug?
Hello, I'm being driven nuts by this problem, I don't know 100% if it's it's a bug or if it's intended behavior, I'm new to D( also new to reporting bugs ) so I can't really tell. Anyway, the problem is, if I call rdmd from outside the folder in which the main source resides in, and main includes another file in that folder, I get an error. example: ...\projectfolder\src\main.d ...\projectfolder\src\test.d // main.d module main; import test.d; void main() { hello(); } // end main.d // test.d module test.d; import std.stdio; void hello() { writeln("Hello"); } // end test.d // If I'm in a shell, and I do this, I get an error: ...\projectfolder>rdmd src\main.d src\main.d(2): Error: module test is in file 'test.d' which cannot be read import path[0] = C:\D\dmd2\windows\bin\..\..\src\phobos import path[1] = C:\D\dmd2\windows\bin\..\..\src\druntime\import // but if I do this, it works: ...\projectfolder\src>rdmd main.d ...\projectfolder\src>Hello world // also works ...\projectfolder\src>dmd main.d test.d Anyway, I want to be able to compile with rdmd from a different folder, is this a bug? or should I use a different tool? :-S *aahhh* Other info: OS: Windows rdmd build 20101220 dmd: 2.050
Re: rdmd executable location
On 12/15/2010 8:58 PM, Nick Voronin wrote: try -of option. rdmd -ofmain main.d works too! Thanks :P
Re: rdmd executable location
Sorry, that should be: rdmd -od%cd%\ filename.d Notice the backslash there. Otherwise it will create an executable on the root drive with the name of the folder you're compiling in. Funky.. Anyway there are more switches here: http://www.digitalmars.com/d/2.0/dmd-windows.html#switches Now that you mentioned it, I did find the executable one folder above where I executed rdmd :P, but what you wrote works, yay. Thanks!
Re: rdmd executable location
If I run it with the rdmd version that came with the compiler, nothing special happens, it just compiles and runs the code, the executable doesn't end up in my current folder. ( rdmd build 20100913 ). If I run it with the compiler version of this code (rdmd build 20101215): http://dsource.org/projects/phobos/browser/trunk/tools/rdmd.d I get an assertion error on line 51, so that doesn't work either.
rdmd executable location
Hello, I'm having a bit of trouble with rdmd. rdmd puts the executable in a temp folder, even with the --build-only option. Maybe this is a silly question but, how can I compile with rdmd so I get the executable in the folder I am currently at? other info: I'm programming in Windows XP with dmd version 2.50
Re: Calling C functions
On 12/9/2010 10:04 PM, Jesse Phillips wrote: CrypticMetaphor Wrote: It is a linker bug, so Oplink is at fault. What is the bug number you submitted? bug number: 5337 http://d.puremagic.com/issues/show_bug.cgi?id=5337
Re: Calling C functions
On 12/9/2010 5:28 PM, Steven Schveighoffer wrote: On Thu, 09 Dec 2010 10:15:59 -0500, CrypticMetaphor wrote: On 12/9/2010 3:57 PM, Steven Schveighoffer wrote: On Thu, 09 Dec 2010 09:37:03 -0500, CrypticMetaphor wrote: I found this page that describes how to call c functions from D. I found this page that describes how: http://arsdnet.net/dtips/#cfunc on that page he uses gcc, and I use dmc, but I get different results. This is what I did // cfile.c file extern int globalFromD; void functionFromC(int a) { globalFromD = a; } // end cfile.c // dfile.d extern(C) { // this is needed to make it available from C int globalFromD; } extern(C) { // also needed when listing the prototypes for your C functions void functionFromC(int); } import std.stdio; // for writefln int main() { globalFromD = 100; writefln("%d", globalFromD); functionFromC(500); writefln("%d", globalFromD); return 0; } // end dfile.d I compile with: dmc -c cfile.c And I get an cfile.obj, which is the object code (.o in gcc). Then I compile the D code dmd dfile.d cfile.obj and I get no errors, so I run it, the result: // start result C:\DCode\libtest>dfile.exe 100 100 C:\DCode\libtest> // end result Why is it still 100? It should be 500. I don't think functionFromC( int ) is being called, and I can't really find any other sources that clearly explain how to do this simple stuff, so can anyone explain how to fix it? I'm guessing that this is a later D2 compiler? If so, then the default storage for globals is in Thread Local Storage (local to each thread). This could explain why it doesn't work, because globalFromD is in TLS in D-land, but in the normal global space in C-land. But there is no declaration of the global-space version then, so I'm surprised it would compile then. I'm really curious why this doesn't work but does compile. What version of D compiler are you using? When using dmd 2.050 on linux I get this error when compiling: ste...@steve-laptop:~/testd$ gcc -c testc.c ste...@steve-laptop:~/testd$ ~/dmd-2.050/linux/bin/dmd testcallc.d testc.o /usr/bin/ld: globalFromD: TLS definition in testcallc.o section .tbss mismatches non-TLS reference in testc.o testc.o: could not read symbols: Bad value collect2: ld returned 1 exit status --- errorlevel 1 Maybe it's a bug in Windows dmd? -Steve Yeah I am using D2 dmc version: 8.42n dmd version: 2.050 Windows XP. But yeah, it compiles here is a screenshot: http://img813.imageshack.us/img813/8230/testu.gif So I gotta read more about threads eh? But that's all the way at the end of the book :-( No, not really. TLS is related to threads, but you don't really have to understand how threads work to understand where things are stored. I don't know where it is in the book, but try looking for Thread Local Storage in the index? But anyway, it should not compile right? Should I submit a bug report or something? Yes please, and be sure to specify that it correctly does not compile on linux. http://d.puremagic.com/issues/enter_bug.cgi And how I supposed to call the c function? Mark the extern(C) integer as __gshared in D. That will put it in the global namespace instead of TLS. e.g.: extern(C) { // this is needed to make it available from C __gshared int globalFromD; } -Steve Alright then! I submitted a my first bug report and added __gshared in front of globalFromD and the output was: 100 500 So it worked. thanks!
Re: Calling C functions
On 12/9/2010 3:57 PM, Steven Schveighoffer wrote: On Thu, 09 Dec 2010 09:37:03 -0500, CrypticMetaphor wrote: I found this page that describes how to call c functions from D. I found this page that describes how: http://arsdnet.net/dtips/#cfunc on that page he uses gcc, and I use dmc, but I get different results. This is what I did // cfile.c file extern int globalFromD; void functionFromC(int a) { globalFromD = a; } // end cfile.c // dfile.d extern(C) { // this is needed to make it available from C int globalFromD; } extern(C) { // also needed when listing the prototypes for your C functions void functionFromC(int); } import std.stdio; // for writefln int main() { globalFromD = 100; writefln("%d", globalFromD); functionFromC(500); writefln("%d", globalFromD); return 0; } // end dfile.d I compile with: dmc -c cfile.c And I get an cfile.obj, which is the object code (.o in gcc). Then I compile the D code dmd dfile.d cfile.obj and I get no errors, so I run it, the result: // start result C:\DCode\libtest>dfile.exe 100 100 C:\DCode\libtest> // end result Why is it still 100? It should be 500. I don't think functionFromC( int ) is being called, and I can't really find any other sources that clearly explain how to do this simple stuff, so can anyone explain how to fix it? I'm guessing that this is a later D2 compiler? If so, then the default storage for globals is in Thread Local Storage (local to each thread). This could explain why it doesn't work, because globalFromD is in TLS in D-land, but in the normal global space in C-land. But there is no declaration of the global-space version then, so I'm surprised it would compile then. I'm really curious why this doesn't work but does compile. What version of D compiler are you using? When using dmd 2.050 on linux I get this error when compiling: ste...@steve-laptop:~/testd$ gcc -c testc.c ste...@steve-laptop:~/testd$ ~/dmd-2.050/linux/bin/dmd testcallc.d testc.o /usr/bin/ld: globalFromD: TLS definition in testcallc.o section .tbss mismatches non-TLS reference in testc.o testc.o: could not read symbols: Bad value collect2: ld returned 1 exit status --- errorlevel 1 Maybe it's a bug in Windows dmd? -Steve Yeah I am using D2 dmc version: 8.42n dmd version: 2.050 Windows XP. But yeah, it compiles here is a screenshot: http://img813.imageshack.us/img813/8230/testu.gif So I gotta read more about threads eh? But that's all the way at the end of the book :-( But anyway, it should not compile right? Should I submit a bug report or something? And how I supposed to call the c function?
Calling C functions
I found this page that describes how to call c functions from D. I found this page that describes how: http://arsdnet.net/dtips/#cfunc on that page he uses gcc, and I use dmc, but I get different results. This is what I did // cfile.c file extern int globalFromD; void functionFromC(int a) { globalFromD = a; } // end cfile.c // dfile.d extern(C) { // this is needed to make it available from C int globalFromD; } extern(C) { // also needed when listing the prototypes for your C functions void functionFromC(int); } import std.stdio; // for writefln int main() { globalFromD = 100; writefln("%d", globalFromD); functionFromC(500); writefln("%d", globalFromD); return 0; } // end dfile.d I compile with: dmc -c cfile.c And I get an cfile.obj, which is the object code (.o in gcc). Then I compile the D code dmd dfile.d cfile.obj and I get no errors, so I run it, the result: // start result C:\DCode\libtest>dfile.exe 100 100 C:\DCode\libtest> // end result Why is it still 100? It should be 500. I don't think functionFromC( int ) is being called, and I can't really find any other sources that clearly explain how to do this simple stuff, so can anyone explain how to fix it?