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 initializers must be runnable at compile time, i.e using CTFE. I've tried to simplify what would be required:

---
extern(C):
char*[] hldr;
enum I = (1<<0);
struct S { char* ft; char** fm; int f; }

void main(){}

enum char[8] FirstLevel  = ['0'];
enum         DoubleLevel = &FirstLevel[0]; // here

S[] s = [
    S(
        FirstLevel.ptr,
DoubleLevel, // error is here actually, interesting
        0),
];
---

D is not able of that :

/tmp/temp_7F835402B0F0.d:9:28: Error: cannot use non-constant CTFE pointer in an initializer `&['0', '\xff', '\xff', '\xff', '\xff', '\xff', '\xff', '\xff'][0]`


Reply via email to