Error: cannot use non-constant CTFE pointer in an initializer `cast(immutable(char)*)TEST`

Tejas notrealemail at gmail.com
Sat Jun 11 11:51:43 UTC 2022


On Saturday, 11 June 2022 at 10:07:46 UTC, test123 wrote:
> how to work this around.
>
> ```d
> __gshared const TEST = import(`onlineapp.d`);
> extern(C) void main(){
>  	__gshared  bin_ptr = TEST.ptr;
> }
> ```
>
> ```sh
> 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:
```d
__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 :(


More information about the Digitalmars-d-learn mailing list