Re: Request assistance initializing struct instance at global scope

2020-12-08 Thread Jacob Carlborg via Digitalmars-d-learn
On Tuesday, 8 December 2020 at 01:47:51 UTC, Andrew Edwards wrote: Thanks Jacob. The extern(C) is temporary. I'm doing a direct port of the code to D using -betterC. Wanted to keep it as close to the original as possible until everything compiles. Yes, that's always a good idea. Do the initia

Re: Request assistance initializing struct instance at global scope

2020-12-07 Thread Andrew Edwards via Digitalmars-d-learn
On 12/7/20 10:56 PM, Adam D. Ruppe wrote: On Monday, 7 December 2020 at 04:13:16 UTC, Andrew Edwards wrote: Given: === extern(C): char*[] hldr; Why is this extern(C)? A D array ere is probably wrong. To stay as close to the original implementation as possible. This will all cha

Re: Request assistance initializing struct instance at global scope

2020-12-07 Thread Andrew Edwards via Digitalmars-d-learn
On 12/7/20 10:12 PM, Jacob Carlborg wrote: On Monday, 7 December 2020 at 04:13:16 UTC, Andrew Edwards wrote: You can either use `extern(C) char*[] hldr` to make only `hldr` have C linkage. Use `extern(C) {}` to group several symbols which should have C linkage or rearrange the code so that `st

Re: Request assistance initializing struct instance at global scope

2020-12-07 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 7 December 2020 at 04:13:16 UTC, Andrew Edwards wrote: Given: === extern(C): char*[] hldr; Why is this extern(C)? A D array ere is probably wrong. In C, a `char*[] hldr = {...}` is actually represented in D as a static length array, like `char*[1] = [null];` It shoul

Re: Request assistance initializing struct instance at global scope

2020-12-07 Thread Jacob Carlborg via Digitalmars-d-learn
On Monday, 7 December 2020 at 04:13:16 UTC, Andrew Edwards wrote: Given: === extern(C): char*[] hldr; enum I = (1<<0); struct S { char* ft; char** fm; int f; } void main(){} === // Error Deprecation: static constructor can only be of D linkage S[] s; static this() {

Re: Request assistance initializing struct instance at global scope

2020-12-06 Thread user1234 via Digitalmars-d-learn
On Monday, 7 December 2020 at 05:28:41 UTC, user1234 wrote: On Monday, 7 December 2020 at 04:13:16 UTC, Andrew Edwards wrote: Given: === extern(C): char*[] hldr; enum I = (1<<0); struct S { char* ft; char** fm; int f; } void main(){} === How do I initialize an instance

Re: Request assistance initializing struct instance at global scope

2020-12-06 Thread user1234 via Digitalmars-d-learn
On Monday, 7 December 2020 at 04:13:16 UTC, Andrew Edwards wrote: Given: === extern(C): char*[] hldr; enum I = (1<<0); struct S { char* ft; char** fm; int f; } void main(){} === How do I initialize an instance of S at global scope? You cant. At the global scope the in

Request assistance initializing struct instance at global scope

2020-12-06 Thread Andrew Edwards via Digitalmars-d-learn
Given: === extern(C): char*[] hldr; enum I = (1<<0); struct S { char* ft; char** fm; int f; } void main(){} === How do I initialize an instance of S at global scope? // Not sure how to do this... so try to keep as close to original as possible // Nope, does not work S