Page 2 of 3
Re: NXC: can't pass expression to ArrayInit
Posted: 17 Jul 2011, 16:57
by afanofosc
BTW, what means "especially of late you are not making me eager to help you or to implement items from your NXC wish list"? why am I late?
"especially of late" means "more than usual right now".
John Hansen
Re: NXC: can't pass expression to ArrayInit
Posted: 17 Jul 2011, 18:31
by muntoo
Just use the workarounds.
Besides, you do realize there's a 256 function/task limit in the firmware? (Kinda sucks, I know.) I don't think that it's easily fixable, since the RXE format will have to change... right?
Re: NXC: can't pass expression to ArrayInit
Posted: 17 Jul 2011, 18:48
by HaWe
though it's OT - yes, you're right, but it's still within the limits of my code.
IIRC RobotC has a limit of main + 19 tasks, that REALLY sucks. Anyhow, it has function overloading.
But no recursion neither.
To show how easy it was if we had recursion to calculate ALL determinates of matrices of ANY size, look at this (cody by Fenris, not optimized yet for development from most efficient row or column):
Code: Select all
void MatrixUntermatrix(float A[][], float R, float S, float R_, float S_, float &B[][])
{
int r, s;
for (s = 0; s < S-1; s++)
{
for (r = 0; r < R-1; r++)
{
B[s][r] = A[s + (s >= S_)][r + (r >= R_)];
}
}
}
float MatrixDeterminanteAllgemein(float A[][], int R)
{
int r;
float U[][];
float det = 0;
if (R == 0) return 1;
else
{
for (r = 0; r < R; r++)
{
MatrixUntermatrix(A, R, R, 0, r, U);
det += (r%2 ? -1 : +1) * A[0][r] * MatrixDeterminante(U, R-1);
}
return det;
}
}
so I have to see that I won't reach the 256 limit nevertheless.
But let's stop getting OT (there's an OT section, I've heard recently )^^
Re: NXC: can't pass expression to ArrayInit
Posted: 17 Jul 2011, 20:06
by muntoo
Use this:
Code: Select all
#define ArrayInitExp(_aout, _val, _cnt) { \
unsigned int _cnt_eval = _cnt; \
asm { arrinit _aout, _val, _cnt_eval } \
}
Or:
Code: Select all
#define ArrayInitExpType(_type, _aout, _val, _cnt) { \
_type _val_eval = _val; \
unsigned int _cnt_eval = _cnt; \
asm { arrinit _aout, _val_eval, _cnt_eval } \
}
P.S. I just realized that
inline
functions don't count towards the 256 limit.
Re: NXC: can't pass expression to ArrayInit
Posted: 17 Jul 2011, 20:22
by HaWe
what does that mean?
Re: NXC: can't pass expression to ArrayInit
Posted: 17 Jul 2011, 20:38
by muntoo
Code: Select all
int arr[];
int a = 4;
int b = 5;
ArrayInitExp(arr, 42, a * b);
// arr[20];
// ArrayInitExpType(int, arr, a / 2 * 21, a * b);
Just paste the
#define
code in my previous post into your program.
Re: NXC: can't pass expression to ArrayInit
Posted: 17 Jul 2011, 20:45
by HaWe
what is this for?
how does it refer to "recursion" or to "pass expressions to asm-code"?
Re: NXC: can't pass expression to ArrayInit
Posted: 17 Jul 2011, 20:50
by hergipotter
You could at least try to understand the code, its not that complicated
With this code you can pass expressions to ArrayInit
Re: NXC: can't pass expression to ArrayInit
Posted: 17 Jul 2011, 20:53
by HaWe
for passing expressions to ArrayInit I don't need that code.
I can simply use a temp variable and pass the temp variable to ArrayInit.
The point is, passing it directly, without having to produce spaghetti (or obfuscated asm) code.
Re: NXC: can't pass expression to ArrayInit
Posted: 17 Jul 2011, 21:10
by muntoo
doc-helmut wrote:The point is, passing it directly, without having to produce spaghetti (or obfuscated asm) code.
Please give an example of what you want. (The implementation.)
Do you want
ArrayInit()
to become the compiler's job? (i.e. "direct" translation, with no
#define
s) I don't see what's wrong with using
#define
s. What difference does it make? NXC will never be "a real C compiler".
Maybe John could put the
ArrayInitExp()
code to replace the current
ArrayInit()
? Would
that be sufficient? I can't see any other ways of doing this. (Excluding
void*
s,
malloc()
, and that sort of stuff. Function overloading wouldn't work too well with multi-dimensional arrays, I believe.)