Re: Capturing by value in the thread

2024-10-18 Thread Steven Schveighoffer via Digitalmars-d-learn
On Friday, 18 October 2024 at 12:07:24 UTC, Kadir Erdem Demir wrote: It seems [=] functionality C++ does not exist in D. No, D does not have this functionality. By using a helper function I made that example work. ```d import std.stdio; auto localFoo(int x) { return (){ return x;}; }

Re: Capturing by value in the thread

2024-10-18 Thread mzfhhhh via Digitalmars-d-learn
On Friday, 18 October 2024 at 12:07:24 UTC, Kadir Erdem Demir wrote: It seems [=] functionality C++ does not exist in D. By using a helper function I made that example work. [...] Because 'work' is captured, it is allocated on the heap. The loops are all assigning values to this 'work' in the

Re: Capturing by value in the thread

2024-10-18 Thread Kagamin via Digitalmars-d-learn
this works for me ``` void aa() { void delegate()[] items; auto captureFuction(int index) { return (){ auto localIndex = index; writeln("index: ", localIndex); }; } for(int i =

Re: Would appreciate some help porting Q3VM to D (mainly C macros and type conversions)

2024-10-18 Thread matheus via Digitalmars-d-learn
On Friday, 18 October 2024 at 14:41:15 UTC, Mark Bauermeister wrote: ...No more segfaults thus far but strangely the proper switch case... One thing that I can think looking at your code: import std.stdio; void main(){ int op = 1; switch(op){ default: writeln("default"); retur

Re: Would appreciate some help porting Q3VM to D (mainly C macros and type conversions)

2024-10-18 Thread Jordan Wilson via Digitalmars-d-learn
On Friday, 18 October 2024 at 14:41:15 UTC, Mark Bauermeister wrote: On Thursday, 17 October 2024 at 02:47:03 UTC, Mai Lapyst wrote: [...] Yea. I forgot about the sizeof division being wrong. I replaced all calls to ARRAY_LEN with \.length. [...] Is the `switch` correct? I would expect to

Re: Would appreciate some help porting Q3VM to D (mainly C macros and type conversions)

2024-10-18 Thread Mark Bauermeister via Digitalmars-d-learn
On Thursday, 17 October 2024 at 02:47:03 UTC, Mai Lapyst wrote: On Wednesday, 16 October 2024 at 13:10:34 UTC, Mark Bauermeister wrote: I think I got every compiler complaint fixed now. However, upon launch the program immediately quits with "Error Program exited with code -11". I assume that's

Capturing by value in the thread

2024-10-18 Thread Kadir Erdem Demir via Digitalmars-d-learn
It seems [=] functionality C++ does not exist in D. By using a helper function I made that example work. ```d import std.stdio; auto localFoo(int x) { return (){ return x;}; } void main() { int x = 10; auto lambda = (int capturedX = x) { writeln("Captured reference : ", ca

Re: Scope & Structs

2024-10-18 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
On 13/10/2024 6:12 PM, Salih Dincer wrote: On Saturday, 12 October 2024 at 13:11:52 UTC, Richard (Rikki) Andrew Cattermole wrote: You are not wrong, when it is a struct, it is being heap allocated. Sorry for prolonging the topic. I am very curious about your answers along with your patience..