当前位置:网站首页>D cannot use a non CTFE pointer

D cannot use a non CTFE pointer

2022-06-12 06:57:00 fqbqrr

original text

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

Try this. :

__gshared  bin_ptr;
shared static this()
{
    // Put it in this ?
    bin_ptr = TEST.ptr;// But this is the overall situation 
}

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


extern(C) void main()
{
    
}

Yes -betterC, Have to use pragma(crt_constructor).
such :

__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()
{
    
}
原网站

版权声明
本文为[fqbqrr]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/163/202206120648566321.html