On Thursday, 6 April 2023 at 00:46:26 UTC, Josh Holtrop wrote:
I am trying to port a small C project to D and am getting a compilation error I don't understand.

It seems like the compiler is just missing some type hints. Try this:

```d
import std.stdio;

__gshared immutable ubyte[4] data = [1, 2, 3, 4];

__gshared immutable ubyte* p = data.ptr;

int main()
{
    writeln("*p = ", *p);
    return 0;
}
```

Look how I provided the `ubyte[4]` hint to the compiler so it thinks that it's a constant.

I'm not sure why this happens, but sometimes the compiler can't deduce static arrays, especially if you're explicitly saying that they're not static (`ubyte[]`).

Reply via email to