Domanda

I have an struct enum, and I use it's values to define an array size; the compiler complains however that the struct's values aren't known at compile time.

module main;

struct Point3D {
        ubyte x;
        ubyte y;
        ubyte z;
}

void main() {
        enum Point3D point = {x:1, y:1, z:1};
        int testArray[point.x][point.y][point.z]; // ERRORS - X Cannot be read at compile time. 
}

The compiler tells me it cannot read x at compile time (it even tells me 4 times). Why is this?

È stato utile?

Soluzione

Looks like a compiler bug... you can work around it by saving the values to intermediary enums:

enum Point3D!ubyte BlobSize = {x:32, y:32, z:32};
enum BlobX = BlobSize.x;
enum BlobY = BlobSize.y;
enum BlobZ = BlobSize.z;
blobcontents[BlobX][BlobY][BlobZ] data;
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top