Re: Using C header libs with importC

2024-01-08 Thread Dennis via Digitalmars-d-learn
On Monday, 8 January 2024 at 21:56:10 UTC, Renato wrote: but I tried exactly that! Which gives a seg fault. Looks like there's a bug with the -H switch: https://issues.dlang.org/show_bug.cgi?id=24326 But that shouldn't be necessary, you should just be able to import the c file. I also

Re: Using C header libs with importC

2024-01-08 Thread Renato via Digitalmars-d-learn
On Monday, 8 January 2024 at 21:04:10 UTC, Dennis wrote: On Monday, 8 January 2024 at 18:53:47 UTC, Renato wrote: Perhaps using an intermediate C file to do this would work, but I wanted to know if D can do it. Yes, your best options are either: - rename the .h to .c and edit it so the

Re: Using C header libs with importC

2024-01-08 Thread Renato via Digitalmars-d-learn
On Monday, 8 January 2024 at 19:17:06 UTC, Lance Bachmeier wrote: On Monday, 8 January 2024 at 18:53:47 UTC, Renato wrote: Is it possible to use C header-only libs from D? In C, I would need to do this: ```c #define STB_DS_IMPLEMENTATION #include "stb_ds.h" ``` The definition must be done in

Re: Doubt about Struct and members

2024-01-08 Thread matheus via Digitalmars-d-learn
On Monday, 8 January 2024 at 17:56:19 UTC, H. S. Teoh wrote: ... It's not recommended to use initializers to initialize mutable array-valued members, because it probably does not do what you think it does. What the above code does is to store the array ["ABC"] somewhere in the program's

Re: Using C header libs with importC

2024-01-08 Thread Lance Bachmeier via Digitalmars-d-learn
On Monday, 8 January 2024 at 18:53:47 UTC, Renato wrote: Is it possible to use C header-only libs from D? In C, I would need to do this: ```c #define STB_DS_IMPLEMENTATION #include "stb_ds.h" ``` The definition must be done in a single C file before including the h file. I tried this in D:

Using C header libs with importC

2024-01-08 Thread Renato via Digitalmars-d-learn
Is it possible to use C header-only libs from D? In C, I would need to do this: ```c #define STB_DS_IMPLEMENTATION #include "stb_ds.h" ``` The definition must be done in a single C file before including the h file. I tried this in D: ```d enum STB_DS_IMPLEMENTATION = 1; import stb_ds; ```

Re: Doubt about Struct and members

2024-01-08 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jan 08, 2024 at 05:28:50PM +, matheus via Digitalmars-d-learn wrote: > Hi, > > I was doing some tests and this code: > > import std; > > struct S{ > string[] s = ["ABC"]; > int i = 123; > } [...] It's not recommended to use initializers to initialize mutable array-valued

Doubt about Struct and members

2024-01-08 Thread matheus via Digitalmars-d-learn
Hi, I was doing some tests and this code: import std; struct S{ string[] s = ["ABC"]; int i = 123; } void foo(bool b, string str){ S t1; writeln("t1.s: ", t1.s, ", t1.s.ptr: ", t1.s.ptr, " t1.i: ", t1.i); if(b){ t1.s[0] = str; }else{ t1.s = [str];

Re: linux dynamic library __gshared var

2024-01-08 Thread d007 via Digitalmars-d-learn
On Monday, 8 January 2024 at 06:12:16 UTC, d007 wrote: I just notice the __gshared is cross process shared. I want a var exits in one process, but shared for multi thread with atomic for __gshared library. how can I do this with d ? my bad, is is process only .