| |
| Posted by Tejas in reply to Tejas | PermalinkReply |
|
Tejas
| On Saturday, 11 June 2022 at 11:51:43 UTC, Tejas wrote:
> On Saturday, 11 June 2022 at 10:07:46 UTC, test123 wrote:
> how to work this around.
__gshared const TEST = import(`onlineapp.d`);
extern(C) void main(){
__gshared bin_ptr = TEST.ptr;
}
dmd2 -betterC -J. onlineapp.d
onlineapp.d(3): Error: cannot use non-constant CTFE pointer in an initializer `cast(immutable(char)*)TEST`
Maybe try putting __gshared bin_ptr = TEST.ptr; inside a shared static this(){} ?
I mean, write it like:
__gshared bin_ptr;
shared static this()
{
bin_ptr = TEST.ptr;
}
__gshared const TEST = import(`onlineapp.d`);
extern(C) void main()
{
}
But bin_ptr becomes a global in this case :(
Oh wait, -betterC is being used ;(
hmm...
Use pragma(crt_constructor) instead
__gshared immutable(char)* bin_ptr;
pragma(crt_constructor)
void init_ptr()
{
bin_ptr = TEST.ptr;
}
__gshared TEST = import("this.d");
extern(C) void main()
{
}
(base) [tejasgarhewal@fedora D]$ ldc2 -J. -betterC this.d
(base) [tejasgarhewal@fedora D]$ ./this
|