d不能用非常ctfe指针

原文

__gshared const TEST = import(`onlineapp.d`);
extern(C) void main(){
     __gshared  bin_ptr = TEST.ptr;
}

试试这个:

__gshared  bin_ptr;
shared static this()
{//放在这个里面?
    bin_ptr = TEST.ptr;//但这个是全局的了
}

__gshared const TEST = import(`onlineapp.d`);


extern(C) void main()
{
}

-betterC,得用pragma(crt_constructor).
这样:

__gshared immutable(char)* bin_ptr;

pragma(crt_constructor)
void init_ptr()
{//pragma
    bin_ptr = TEST.ptr;
}

__gshared TEST = import("this.d");

extern(C) void main()
{
}
posted @ 2022-06-11 22:09  zjh6  阅读(17)  评论(0)    收藏  举报  来源