| Author |
Message |
|
Talavasu
Rookie
Joined: Thu May 29, 2008 4:46 am Posts: 3
|
 Array as function parameter?
Hi,
I need matrix functions for a bachelor thesis concerning special calculations on a NXT. As I couldn't find any RobotC headers for matrix funtions in the web, I decided to write my own one. However, I didn't find a solution to use arrays as function parameters. Every time I get an error message.
Is there any method to pass an array to a function?
Perhaps I could use the pointer of the array and cast it afterwards but I don't know how to do it in RobotC.
I'm an experienced programmer, so please tell me whatever ideas you have no matter how complex they are.
Thank you.
P.S.: In previous articles some of you sugested to wrap the array in a struct-statement. The problem with this way is that you have to define a specific array size.
|
| Thu May 29, 2008 10:36 am |
|
 |
|
Ford Prefect
Senior Roboticist
Joined: Sat Mar 01, 2008 12:52 pm Posts: 936 Location: a small planet in the vicinity of Beteigeuze
|
hi,
I got an idea by defining a structure containing an array, but I don't know if it's the ultimate way, and I still have not tested the code.
Maybe there will be a much easier way...
_________________ Ford Prefect
Never purchase release 1.x ! (ancient programmer's wisdom) "Don't argue with idiots. They'll drag you down to their level and then beat you with experience."
Last edited by Ford Prefect on Thu May 29, 2008 2:22 pm, edited 1 time in total.
|
| Thu May 29, 2008 11:17 am |
|
 |
|
Talavasu
Rookie
Joined: Thu May 29, 2008 4:46 am Posts: 3
|
Thank you for your reply, Ford Prefect. However, your idea restricts the function only to work with a fixed array size. I need a matrix multiplication for matrices of any size.
|
| Thu May 29, 2008 11:29 am |
|
 |
|
Ford Prefect
Senior Roboticist
Joined: Sat Mar 01, 2008 12:52 pm Posts: 936 Location: a small planet in the vicinity of Beteigeuze
|
Hi Talavasu,
did you know that RobotC supports only 2 dimensional matrices?
if this fits, you may wish to define several multiplation functions depending on the sizes of the matrices (anyway, you may overload the definitions), since even dynamic memory addressing is not possible with RobotC...
_________________ Ford Prefect
Never purchase release 1.x ! (ancient programmer's wisdom) "Don't argue with idiots. They'll drag you down to their level and then beat you with experience."
|
| Thu May 29, 2008 12:00 pm |
|
 |
|
Talavasu
Rookie
Joined: Thu May 29, 2008 4:46 am Posts: 3
|
2D-arrays are enough for me. So that's fine.
Instead of multiple functions I decided to use the maximum number of rows and columns in the type definition. As my matrices don't vary much in their size, this would be okay. Surprisingly this works quite well as long as I use only an int array.
When I use an array with floating point values and change one value of an array element in the multiplication function, the display of my NXT freezes and the NXT can't be turned of anymore. Furthermore I hear a gentle knocking. The only solution in this situation is to push the reset button.
I wonder why this doesn't work with floating point values. Unfortunately I need them.
Edited: I fixed the problem by using RobotC 1.30 Beta 4. Now it works even with floating point values. 
Last edited by Talavasu on Fri May 30, 2008 6:45 am, edited 1 time in total.
|
| Fri May 30, 2008 6:07 am |
|
 |
|
Ford Prefect
Senior Roboticist
Joined: Sat Mar 01, 2008 12:52 pm Posts: 936 Location: a small planet in the vicinity of Beteigeuze
|
which release do you have?
I had the same trouble using 1.30 beta 2, but not any longer with 1.30 beta 4 .
(ok, there are other bugs with arrays as part of structures, or arrays of structures, or both, but not with arithmetic operations like multiplication or even exponential functions)
... and did you change the format string of the print command...?
[EDIT:] as I just have watched, you meanwhile got it... 
_________________ Ford Prefect
Never purchase release 1.x ! (ancient programmer's wisdom) "Don't argue with idiots. They'll drag you down to their level and then beat you with experience."
|
| Fri May 30, 2008 6:44 am |
|
 |
|
Dick Swan
Creator
Joined: Fri Feb 09, 2007 9:21 am Posts: 613
|
There were compiler problems with array variables as function parameters in earlier releases. I think verison 1.37 has cleared all or most of these up.
There were also problems with struct elements when they weren't simple "ints". The compiler code generator was not properly looking at the variable type and they were defaulting to "int". I believe this was fixed around version 1.30.
Since many ROBOTC users are novice programmers there was an early decision not to support pointers in ROBOTC. And also a decision to extend "C" to support call by reference function parameters with the use of the "&" operator found in C++. This worked fine foir some time but I realized earlier this year that there really was a need for pointers. Pointer support has slowly been added to ROBOTC but is not yet totally bug-free. Sorry. : 
|
| Wed Jun 04, 2008 5:22 am |
|
|