Re: Returning value by ref does not create a ref. Is this intentional?

2022-01-04 Thread Tejas via Digitalmars-d-learn
On Wednesday, 5 January 2022 at 05:17:10 UTC, Stanislav Blinov wrote: It is returned. But initializing `c` with it makes a copy. Oh... Wish we had real `ref` ;( This will mutate `a`: ``` func(a) = 10; ``` Thank you for your help!

Re: Returning value by ref does not create a ref. Is this intentional?

2022-01-04 Thread Tejas via Digitalmars-d-learn
On Wednesday, 5 January 2022 at 05:15:30 UTC, Paul Backus wrote: On Wednesday, 5 January 2022 at 04:35:12 UTC, Tejas wrote: ```d import std.stdio:writeln; ref int func(return ref int a){ a = 6; // modifies a as expected return a; } void main(){ int a = 5; auto c = func(a); // I

Re: Returning value by ref does not create a ref. Is this intentional?

2022-01-04 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 5 January 2022 at 04:35:12 UTC, Tejas wrote: ```d import std.stdio:writeln; ref int func(return ref int a){ a = 6; // modifies a as expected return a; } void main(){ int a = 5; auto c = func(a); // I expected c to alias a here c = 10; // Expected to modify a as

Re: Returning value by ref does not create a ref. Is this intentional?

2022-01-04 Thread Stanislav Blinov via Digitalmars-d-learn
On Wednesday, 5 January 2022 at 04:35:12 UTC, Tejas wrote: ```d import std.stdio:writeln; ref int func(return ref int a){ a = 6; // modifies a as expected return a; } void main(){ int a = 5; auto c = func(a); // I expected c to alias a here c = 10; // Expected to modify a as

Returning value by ref does not create a ref. Is this intentional?

2022-01-04 Thread Tejas via Digitalmars-d-learn
```d import std.stdio:writeln; ref int func(return ref int a){ a = 6; // modifies a as expected return a; } void main(){ int a = 5; auto c = func(a); // I expected c to alias a here c = 10; // Expected to modify a as well writeln(a); // prints 6 :( } ``` The

Re: Libc functions undefined when linking

2022-01-04 Thread Tejas via Digitalmars-d-learn
On Tuesday, 4 January 2022 at 18:13:56 UTC, Ben Jones wrote: The tricky part is that the lab machines that the students will be using don't have a D compiler installed (they're Fedora machines, and I didn't see a dmd package in their repos, or I would have asked the admins to install it).

Re: what is going on here?

2022-01-04 Thread forkit via Digitalmars-d-learn
On Tuesday, 4 January 2022 at 23:37:57 UTC, H. S. Teoh wrote: ... .. . Which seems to confirm my suspicions. T yes, this sounds like it might be it. I tried using = void; .. results: dmd -m64 -> just results in an 'out of memory' message (but at least i get a message this time) ldc2

Re: what is going on here?

2022-01-04 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jan 04, 2022 at 03:34:41PM -0800, H. S. Teoh wrote: [...] > Of course, afterwards the optimizer would merge them into something > saner, but while the compiler is unfolding all those assignments, its > memory usage would obviously skyrocket. Or the compiler would run out of memory before

Re: what is going on here?

2022-01-04 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jan 04, 2022 at 10:53:50PM +, forkit via Digitalmars-d-learn wrote: [...] > // > > module test; > void main(){ static char[2147483646] arr; } > > // I bet you it's the same problem I found a couple of years ago, where the compiler translates the above code to something

what is going on here?

2022-01-04 Thread forkit via Digitalmars-d-learn
strange things happen when I compile (on windows) the code below with: dmd -m64 (compilation just crashes - no error message at all) or ldc2 -m64 (compilation works, but memory usage during compilation goes completely wild! upto 22GB, then down to 7GB, then finally completes.) //

Module without object file?

2022-01-04 Thread kdevel via Digitalmars-d-learn
In a project I have this "controller" function: ``` void create_fso (O) (Request req) { : auto npathname = (extract name from req) : O.create (npathname); : } public import fsobjects; ``` which creates a file system object. The possible object types I collected in a separate

Re: Libc functions undefined when linking

2022-01-04 Thread Ben Jones via Digitalmars-d-learn
On Tuesday, 4 January 2022 at 21:34:46 UTC, Adam D Ruppe wrote: On Tuesday, 4 January 2022 at 21:22:26 UTC, Ben Jones wrote: * frame #0: 0x That's null, meaning the library wasn't loaded. simpledisplay actually doesn't need -lX11 since it always dynamic loads the

Re: Libc functions undefined when linking

2022-01-04 Thread Adam D Ruppe via Digitalmars-d-learn
On Tuesday, 4 January 2022 at 21:22:26 UTC, Ben Jones wrote: * frame #0: 0x That's null, meaning the library wasn't loaded. simpledisplay actually doesn't need -lX11 since it always dynamic loads the libraries. Normally it throws when this fails though instead of keeping

Re: Libc functions undefined when linking

2022-01-04 Thread Ben Jones via Digitalmars-d-learn
On Tuesday, 4 January 2022 at 20:28:00 UTC, Ben Jones wrote: On Tuesday, 4 January 2022 at 19:14:04 UTC, Adam D Ruppe wrote: [...] Crashes on `display = XOpenDisplay(displayName);` : ``` * thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0) *

Re: Libc functions undefined when linking

2022-01-04 Thread bachmeier via Digitalmars-d-learn
On Tuesday, 4 January 2022 at 18:13:56 UTC, Ben Jones wrote: be using don't have a D compiler installed (they're Fedora machines, and I didn't see a dmd package in their repos, or I would have asked the admins to install it). Just for the record, while the official Fedora repos don't have

Re: Libc functions undefined when linking

2022-01-04 Thread Ben Jones via Digitalmars-d-learn
On Tuesday, 4 January 2022 at 19:14:04 UTC, Adam D Ruppe wrote: On Tuesday, 4 January 2022 at 19:10:25 UTC, Ben Jones wrote: All good, except now simpledisplay is segfaulting on XDisplayConnection.get again run it in the debugger; do a -g build and run it in gdb or lldb and do check the

Re: what's the proper way to assign this?

2022-01-04 Thread Dr Machine Code via Digitalmars-d-learn
On Tuesday, 4 January 2022 at 19:06:52 UTC, Ali Çehreli wrote: On 1/4/22 10:53 AM, Dr Machine Code wrote: what made that change, assuming it worked at time. Library? compile changes? Here is the changelog item: https://dlang.org/changelog/2.088.0.html#remove-nullable-alias-get-this A

Re: Libc functions undefined when linking

2022-01-04 Thread Adam D Ruppe via Digitalmars-d-learn
On Tuesday, 4 January 2022 at 19:10:25 UTC, Ben Jones wrote: All good, except now simpledisplay is segfaulting on XDisplayConnection.get again run it in the debugger; do a -g build and run it in gdb or lldb and do check the exact line it is on. could be that the Xlib things didn't

Re: Libc functions undefined when linking

2022-01-04 Thread Ben Jones via Digitalmars-d-learn
On Tuesday, 4 January 2022 at 18:45:37 UTC, Ben Jones wrote: On Tuesday, 4 January 2022 at 18:37:25 UTC, Adam D Ruppe wrote: On Tuesday, 4 January 2022 at 18:13:56 UTC, Ben Jones wrote: clang -c -o source/assignment1.o source/assignment1.c you might have better luck just telling clang to

Re: what's the proper way to assign this?

2022-01-04 Thread Ali Çehreli via Digitalmars-d-learn
On 1/4/22 10:53 AM, Dr Machine Code wrote: what made that change, assuming it worked at time. Library? compile changes? Here is the changelog item: https://dlang.org/changelog/2.088.0.html#remove-nullable-alias-get-this A reminder at least to myself: I found it by searching for Nullable in

Re: what's the proper way to assign this?

2022-01-04 Thread Dr Machine Code via Digitalmars-d-learn
On Tuesday, 4 January 2022 at 17:58:05 UTC, Adam D Ruppe wrote: On Tuesday, 4 January 2022 at 17:23:11 UTC, Dr Machine Code wrote: I could fix just with ```d data.entries ~= entry.get; ``` This is what the original code was doing - it used to implicitly do this. So while this

Re: Is there a File-like object for unit tests?

2022-01-04 Thread Amit via Digitalmars-d-learn
Wow, several different approaches! Thanks everyone, I find this discussion enriching. I find `H. S. Teoh`'s template solution to be the closest to what I need. It adds minimal complexity to the existing implementation.

Re: Libc functions undefined when linking

2022-01-04 Thread Ben Jones via Digitalmars-d-learn
On Tuesday, 4 January 2022 at 18:37:25 UTC, Adam D Ruppe wrote: On Tuesday, 4 January 2022 at 18:13:56 UTC, Ben Jones wrote: clang -c -o source/assignment1.o source/assignment1.c you might have better luck just telling clang to link it too like clang source/assignment1.o -lphobos2 build/*.o

Re: Libc functions undefined when linking

2022-01-04 Thread Adam D Ruppe via Digitalmars-d-learn
On Tuesday, 4 January 2022 at 18:13:56 UTC, Ben Jones wrote: clang -c -o source/assignment1.o source/assignment1.c you might have better luck just telling clang to link it too like clang source/assignment1.o -lphobos2 build/*.o # etc since there's a bunch of default search paths and libs

Re: Libc functions undefined when linking

2022-01-04 Thread Ali Çehreli via Digitalmars-d-learn
On 1/4/22 10:13 AM, Ben Jones wrote: > So I think I need to specify that I want to explicitly include libc when > I link it. `-lc` didn't seem to work. Did you add -lc and -lpthread on the linker line? > ld build/*.o -L. -lphobos2 -o build/executable Ali

Re: Libc functions undefined when linking

2022-01-04 Thread Ben Jones via Digitalmars-d-learn
On Tuesday, 4 January 2022 at 18:26:41 UTC, Ali Çehreli wrote: On 1/4/22 10:13 AM, Ben Jones wrote: > So I think I need to specify that I want to explicitly include libc when > I link it. `-lc` didn't seem to work. Did you add -lc and -lpthread on the linker line? > ld build/*.o -L.

Libc functions undefined when linking

2022-01-04 Thread Ben Jones via Digitalmars-d-learn
I have a somewhat unusual use case and I'm having trouble getting everything to link properly. I'm writing an assignment for a course I'm teaching and I've written the skeleton code in D, and students are going to implement one function in C, which my skeleton code will call. The tricky

Re: Is there a File-like object for unit tests?

2022-01-04 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jan 04, 2022 at 05:01:41PM +, Amit via Digitalmars-d-learn wrote: > Hi! > > I wrote a text parser that takes a File argument and parses that > file's contents. Now I would like to write a unit-test for that > parser. I need a File (or a general IO interface) that reads from an >

Re: Is there a File-like object for unit tests?

2022-01-04 Thread Ali Çehreli via Digitalmars-d-learn
On 1/4/22 9:48 AM, Paul Backus wrote: > On Tuesday, 4 January 2022 at 17:01:41 UTC, Amit wrote: >> I need a File (or a general IO interface) that reads from an >> in-memory buffer, similar to python's `StringIO` or go's >> `strings.Reader`. >> >> How can I achieve that? I don't think it exists

Re: what's the proper way to assign this?

2022-01-04 Thread Adam D Ruppe via Digitalmars-d-learn
On Tuesday, 4 January 2022 at 17:23:11 UTC, Dr Machine Code wrote: I could fix just with ```d data.entries ~= entry.get; ``` This is what the original code was doing - it used to implicitly do this. So while this might be buggy, it wouldn't be a new bug at least.

Re: Is there a File-like object for unit tests?

2022-01-04 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 4 January 2022 at 17:01:41 UTC, Amit wrote: Hi! I wrote a text parser that takes a File argument and parses that file's contents. Now I would like to write a unit-test for that parser. I need a File (or a general IO interface) that reads from an in-memory buffer, similar to

what's the proper way to assign this?

2022-01-04 Thread Dr Machine Code via Digitalmars-d-learn
I've tried to build 2 years old D project and I was getting the error: > Error: cannot append type `Nullable!(SelectorEntry)` to type `SelectorEntry[]` I went to use Nullable, 'cause I've never used it before. Boiling down the error was something like (minimal code reproduction): ```d

Is there a File-like object for unit tests?

2022-01-04 Thread Amit via Digitalmars-d-learn
Hi! I wrote a text parser that takes a File argument and parses that file's contents. Now I would like to write a unit-test for that parser. I need a File (or a general IO interface) that reads from an in-memory buffer, similar to python's `StringIO` or go's `strings.Reader`. How can I