does the arduino IDE support 3D arrays?

Hello, I am new to this form and I have been working with Arduino for a month now. I has been a great experience so far even with my limited knowledge of C.

I am however having great difficulties now trying to work with 3 dimensional arrays. After doing a fair amount of googling I am curious if the arduino C compiler supports 3D arrays at all?

as well as this post which i cant quite understand:
https://code.google.com/p/arduino/issues/detail?id=233#c1

I have noticed that there is another post on this forum discussing the initialization of a 3D array.
However I have tried using the code suggested in the followup post and cannot get it to work. The code compiles without error, however my serial terminal does not show any data, it is only spammed with "test"

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1220238747

The code I am using to test with.

boolean patterns[2][4][4]=
{
 {
   {1, 1, 1, 1},
   {1, 1, 1, 1},
   {1, 1, 1, 1},
   {1, 1, 1, 1}
 },
 {
   {0, 0, 0, 0},
   {0, 0, 0, 0},
   {0, 0, 0, 0},
   {0, 0, 0, 0}
 }
};

void setup() {
  
        Serial.begin(115200);
}

void loop() {
  
  Serial.print("test");
  Serial.println(patterns[0][2][2]);

  delay(1000);
}

What my terminal shows:
"test
test
test
test
test
test
test
test
test
"
However my serial terminal does not display that matrix like symbol after the "test" text that just appeared when I pasted the output of the serial terminal in here. :-?

What do expect the program to "print" for a boolean?

ugggh, now I feel silly, I changed the array to an int and its working. :smiley: Thank You!

I had expected to just see a 0 or 1, does this not convert to a char nicely?

On that note, what was printing? A blank space shows in my terminal as a result of " Serial.println(patterns[1][2][2]);" however when I copy that blank space over into this post it showed as the matrix symbol above. Is this some extended ASCII character?

It was "printing" either the character whose ASCII code was 1 or the character whose ASCII code was 0, depending on whether the value was true or false.

Since neither 0 or 1 are printable ASCII values, it's hard to know why that strange symbol appeared when you pasted the code.

Converting the array to 'int' is OK but now each value takes up 2 bytes instead of 1 byte. If you're going to work with 3-D arrays they are going to consume your limited RAM very quickly, so consider how much size they take up carefully.

If your arrays are only going to hold small numbers (that can fit into 8 bits) you're better off declaring the array as "unsigned char" (for numbers 0 to 255) or "signed char" (for numbers -128 to 127). Then each array element only takes 1 byte.

Then, to print them out:

Serial.println((unsigned) patterns[1][2][2]);

for unsigned numbers, or:

Serial.println((int) patterns[1][2][2]);

for signed numbers.

--
Check out our new shield: http://www.ruggedcircuits.com/html/gadget_shield.html