initializing 4-dimensional array

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
Post Reply
sharpsee
Posts: 3
Joined: 24 Nov 2011, 07:22

initializing 4-dimensional array

Post by sharpsee »

I'm having trouble initializing a 4-dimensional array in nxc bricxcc. A little while ago, I hooked on to this topic. I've tried the steps presented here by muntoo, but they didn't work. Without any hope for it to work, I also tried with the NXT connected via USB. I don't need the 4-dimensoinal array, but having it would make my life a lot easier.
To be sure that nothing is wrong woth my array, I've tested with

Code: Select all

task main() 
{
int MyArray[][][][] = {
  {
    {{0, -1},{1, -1}},
    {{2, -1},{3, -1}}
  },
  {
    {{10, 11},{12, 13}},
    {{20, 21},{23, 31}}
  }
};
}
The error I'm getting is "Line12: Error: Error parsing expression: } Line12: Error: Error parsing expression: } }"
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: initializing 4-dimensional array

Post by HaWe »

I would do it this way:
define the correct size from the start, e.g.
int MyArray[2][2][2][2];

then I initialize it step by step:
MyArray[0][0][0][0]=0;
MyArray[1][0][0][0]=1;
MyArray[0][1][0][0]=2;
MyArray[1][1][0][0]=3;
MyArray[0][0][1][0]=4;
MyArray[1][0][1][0]=5;
...
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: initializing 4-dimensional array

Post by afanofosc »

When I get around to posting my latest version of the compiler/IDE then you will be able to use your C-style initialization code. Or you could send me a regular email to the address in the About box and I could hook you up with a newer build than is currently available on line.

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: initializing 4-dimensional array

Post by afanofosc »

P.S., how exactly would having a 4-d array make your life a lot easier?

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: initializing 4-dimensional array

Post by HaWe »

You are talking from my soul (don't know if you understand this idiom) -
i personally actually was afraid to ask this question.
4 dimensions are sort of beyond my imagination although I must admit that my imagination is limited.
mightor
Site Admin
Posts: 1079
Joined: 25 Sep 2010, 15:02
Location: Rotterdam, Netherlands
Contact:

Re: initializing 4-dimensional array

Post by mightor »

P.S., how exactly would having a 4-d array make your life a lot easier?
Perhaps he's not from Earth and needs this kind of 4D math to allow him to travel back to his own dimension.

Anything's possible, right?

- Xander
| My Blog: I'd Rather Be Building Robots (http://botbench.com)
| RobotC 3rd Party Driver Suite: (http://rdpartyrobotcdr.sourceforge.net)
| Some people, when confronted with a problem, think, "I know, I'll use threads,"
| and then two they hav erpoblesms. (@nedbat)
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: initializing 4-dimensional array

Post by afanofosc »

I've uploaded a new test release (20111212) to http://bricxcc.sourceforge.net/test_releases/

See if this version successfully compiles the 4-d array initialization code above. In theory, it should.

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest