Re: translate C struct char array into D

2021-08-02 Thread workman via Digitalmars-d-learn
On Friday, 30 July 2021 at 21:53:48 UTC, russhy wrote: On Friday, 30 July 2021 at 14:05:58 UTC, workman wrote: I get want to define this struct in D: ```c struct test1 { struct test1 *prev; struct test1 *next; size_t v1; size_t v2; size_t v3; char data[]; }; ``` ```d st

Re: translate C struct char array into D

2021-07-30 Thread russhy via Digitalmars-d-learn
On Friday, 30 July 2021 at 14:05:58 UTC, workman wrote: I get want to define this struct in D: ```c struct test1 { struct test1 *prev; struct test1 *next; size_t v1; size_t v2; size_t v3; char data[]; }; ``` ```d struct test1 { test1 *prev; test1 *next; size_

Re: translate C struct char array into D

2021-07-30 Thread jfondren via Digitalmars-d-learn
On Friday, 30 July 2021 at 14:05:58 UTC, workman wrote: I get want to define this struct in D: ```c struct test1 { struct test1 *prev; struct test1 *next; size_t v1; size_t v2; size_t v3; char data[]; }; ``` The easy way: put a slice there instead of a fake array and a

Re: translate C struct char array into D

2021-07-30 Thread Paul Backus via Digitalmars-d-learn
On Friday, 30 July 2021 at 15:51:12 UTC, Tejas wrote: On Friday, 30 July 2021 at 14:40:17 UTC, Paul Backus wrote: On Friday, 30 July 2021 at 14:05:58 UTC, workman wrote: [...] `char data[]` in the C struct is not a pointer, but actually a [C99 flexible array member][1], and does not count to

Re: translate C struct char array into D

2021-07-30 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jul 30, 2021 at 03:41:32PM +, Tejas via Digitalmars-d-learn wrote: > On Friday, 30 July 2021 at 14:40:17 UTC, Paul Backus wrote: [...] > > ```d > > struct test1 { > > // member variables... > > > > char* data() { > > return cast(char*) (&this + 1); > > } > > } > > `

Re: translate C struct char array into D

2021-07-30 Thread Tejas via Digitalmars-d-learn
On Friday, 30 July 2021 at 14:40:17 UTC, Paul Backus wrote: On Friday, 30 July 2021 at 14:05:58 UTC, workman wrote: [...] `char data[]` in the C struct is not a pointer, but actually a [C99 flexible array member][1], and does not count towards the struct's `sizeof`. D does not have flexibl

Re: translate C struct char array into D

2021-07-30 Thread Tejas via Digitalmars-d-learn
On Friday, 30 July 2021 at 14:40:17 UTC, Paul Backus wrote: On Friday, 30 July 2021 at 14:05:58 UTC, workman wrote: [...] `char data[]` in the C struct is not a pointer, but actually a [C99 flexible array member][1], and does not count towards the struct's `sizeof`. D does not have flexibl

Re: translate C struct char array into D

2021-07-30 Thread Paul Backus via Digitalmars-d-learn
On Friday, 30 July 2021 at 14:05:58 UTC, workman wrote: I get want to define this struct in D: ```c struct test1 { struct test1 *prev; struct test1 *next; size_t v1; size_t v2; size_t v3; char data[]; }; ``` ```d struct test1 { test1 *prev; test1 *next; size_

translate C struct char array into D

2021-07-30 Thread workman via Digitalmars-d-learn
I get want to define this struct in D: ```c struct test1 { struct test1 *prev; struct test1 *next; size_t v1; size_t v2; size_t v3; char data[]; }; ``` ```d struct test1 { test1 *prev; test1 *next; size_t v1; size_t v2; size_t v3; char* data; }; ``