Request assistance initializing struct instance at global scope
Andrew Edwards
edwards.ac at gmail.com
Mon Dec 7 04:13:16 UTC 2020
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[] s = [
{
cast(char*)"c",
&hldr[0],
I
},
]
// Error: static variable C_HL_extensions cannot be read at compile time
S[] s = [ S(cast(char*)"c", &hldr[0], I) ];
// Error Deprecation: static constructor can only be of D linkage
S[] s;
static this() {
s = [ S(cast(char*)"c", &hldr[0], I) ];
}
Thanks,
Andrew
More information about the Digitalmars-d-learn
mailing list