# 3-dimensional array problem

Hi all,

I’m programming my own 3D LED cube and I’m trying having issues with passing a multi-dimensional array to a function. I defined

byte LEDarray[8][8][8];

and assigned a zero to every index

for (int x = 0; x < 8; x++) {
for (int y = 0; y < 8; y++) {
for (int z = 0; z < 8; z++) {
LEDarray[y][z] = 0;
}
}
}

and when I try to pass it to a function

translateLEDarray(LEDarray);

void translateLEDarray (byte* arrayXYZ) {

}

it gives me this error

error: cannot convert ‘byte ()[8][8]’ to 'byte’ for argument ‘1’ to ‘void translateLEDarray(byte*)’

easiest: you might just keep the 3D array a global var...

You could define your function to match the style of the array you’re passing thus:

``````void translateLEDarray (byte arrayXYZ[8][8][8])
``````

KenF: You could define your function to match the style of the array you're passing thus:

``````void translateLEDarray (byte arrayXYZ[8][8][8])
``````

Or:

``````void translateLEDarray(byte ***arrayXYZ)
``````

Wow, awesome information, I'm enlightened, thank you! :-)

The compiler needs to know where to "fold" the array to properly walk through it. Given the code:

``````#define LEDSPERSIDE   8

byte LEDarray[LEDSPERSIDE][LEDSPERSIDE][LEDSPERSIDE];
``````

means the array of 512 bytes is "folded" every 8 bytes. Because of the way compiler treats arrays, it needs to have all but the first rank to properly walk through the array. Therefore, your function could use one of Paul's ways to format the function's signature, or you could also use:

``````void translateLEDarray (byte arrayXYZ[][LEDSPERSIDE][LEDSPERSIDE]) {
// code for the function
}
``````

Note that the first rank can be left blank. All others must be supplied so the compiler can figure things out.

Okay, another question: the array only needs to be 512 bits, one bit per led, how would I acheive that?

``````byte myarray[64] = {0b00010001, 0b10001000,...  ...};