Re: Memory leak issue between extern (c) and D function

2023-04-13 Thread Paul Backus via Digitalmars-d-learn
On Friday, 14 April 2023 at 03:50:37 UTC, backtrack wrote: Dear All, I am new to D lang. I have been given a task to consume the .dll generated from a D lang project. I added extern (c) function for call the .dll from CPP file. i have code like below ``` // myfile.d extern(c) { mystruc

Memory leak issue between extern (c) and D function

2023-04-13 Thread backtrack via Digitalmars-d-learn
Dear All, I am new to D lang. I have been given a task to consume the .dll generated from a D lang project. I added extern (c) function for call the .dll from CPP file. i have code like below ``` // myfile.d extern(c) { mystruct* getmystruct() { mystruct* mystruct = cast(m

Re: How to setup D with SFML? (using bindbc-sfml)

2023-04-13 Thread Salih Dincer via Digitalmars-d-learn
On Friday, 14 April 2023 at 00:28:53 UTC, Ki Rill wrote: ``` LINK : fatal error LNK1104: cannot open file 'libucrt.lib' Error: linker exited with status 1104 ``` Why does it require this library and where can I find it? Since this library is a component of the Microsoft C Runtime (CRT) librar

Re: Returning a reference to be manipulated

2023-04-13 Thread kdevel via Digitalmars-d-learn
On Thursday, 13 April 2023 at 22:09:48 UTC, Jacob Shtokolov wrote: [...] ref opIndex(string key) return [...] Regarding the return ref I found this code of 2019 on my harddisk which is from or was motivated by a dconf talk: ``` ref int foo (ref int i) { return i; } ref int bar () {

Re: How to setup D with SFML? (using bindbc-sfml)

2023-04-13 Thread Ki Rill via Digitalmars-d-learn
On Wednesday, 12 April 2023 at 10:05:14 UTC, Salih Dincer wrote: On Tuesday, 11 April 2023 at 10:24:09 UTC, Ki Rill wrote: If you wanted static I would add and run libraries easy, like this: ```Json "libs": [ "csfml-audio", "csfml-graphics" ],

Re: Returning a reference to be manipulated

2023-04-13 Thread Jacob Shtokolov via Digitalmars-d-learn
On Thursday, 13 April 2023 at 07:05:10 UTC, Chris Katko wrote: I'm trying to figure out how to return a reference to something that may not be a reference type. ```d @safe: struct Stats { float[string] data; ref opIndex(string key) return { // The `require()` takes care of

Re: Returning a reference to be manipulated

2023-04-13 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 13 April 2023 at 07:05:10 UTC, Chris Katko wrote: Right now, I'm using pointers which resolves to: ```D // float* opIndex(string key){...} using pointer (*s["tacos"])++; // works with pointer, but is strange looking s["tacos"]++; // preferred syntax or something similar ``` You c

Re: Returning a reference to be manipulated

2023-04-13 Thread IchorDev via Digitalmars-d-learn
On Thursday, 13 April 2023 at 07:05:10 UTC, Chris Katko wrote: I'm trying to figure out how to return a reference to something that may not be a reference type. ```D struct stats { float[string] data=0; float ref opIndex(string key) { return data[key]; // want a ref to a specific element

Re: How can a function pointer required to be extern(C)?

2023-04-13 Thread rempas via Digitalmars-d-learn
On Wednesday, 12 April 2023 at 21:00:04 UTC, John Chapman wrote: You can also express it like this: ```d extern(C) alias FuncPtr = void* function(void*); ``` Thank you! This is how I was planning to do anyway because other that the fact that I like the syntax of that a little bit more, this

Re: How can a function pointer required to be extern(C)?

2023-04-13 Thread rempas via Digitalmars-d-learn
On Wednesday, 12 April 2023 at 20:36:59 UTC, H. S. Teoh wrote: IMO this is a bug either in D's syntax or in the parser. I'd file an enhancement request. In the meantime, you can use alias as a workaround: ---snip--- extern(C) void* abc(void*) {return null;} alias FuncPtr = typeof(

Returning a reference to be manipulated

2023-04-13 Thread Chris Katko via Digitalmars-d-learn
I'm trying to figure out how to return a reference to something that may not be a reference type. ```D struct stats { float[string] data=0; float ref opIndex(string key) { return data[key]; // want a ref to a specific element } } void test() { stats foo; auto x = foo.bar(); // returns so