NXC: can't pass expression to ArrayInit

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: NXC: can't pass expression to ArrayInit

Post 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
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
muntoo
Posts: 834
Joined: 01 Oct 2010, 02:54
Location: Your Worst Nightmare
Contact:

Re: NXC: can't pass expression to ArrayInit

Post 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?
Image

Commit to LEGO Mindstorms Robotics Stack Exchange:
bit.ly/MindstormsSE


Commit to LEGO Stack Exchange: bit.ly/Area51LEGOcommit
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: NXC: can't pass expression to ArrayInit

Post 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 )^^
muntoo
Posts: 834
Joined: 01 Oct 2010, 02:54
Location: Your Worst Nightmare
Contact:

Re: NXC: can't pass expression to ArrayInit

Post 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. :)
Image

Commit to LEGO Mindstorms Robotics Stack Exchange:
bit.ly/MindstormsSE


Commit to LEGO Stack Exchange: bit.ly/Area51LEGOcommit
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: NXC: can't pass expression to ArrayInit

Post by HaWe »

what does that mean?
muntoo
Posts: 834
Joined: 01 Oct 2010, 02:54
Location: Your Worst Nightmare
Contact:

Re: NXC: can't pass expression to ArrayInit

Post 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.
Image

Commit to LEGO Mindstorms Robotics Stack Exchange:
bit.ly/MindstormsSE


Commit to LEGO Stack Exchange: bit.ly/Area51LEGOcommit
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: NXC: can't pass expression to ArrayInit

Post by HaWe »

what is this for?
how does it refer to "recursion" or to "pass expressions to asm-code"?
hergipotter
Posts: 48
Joined: 12 Jan 2011, 18:40
Contact:

Re: NXC: can't pass expression to ArrayInit

Post by hergipotter »

You could at least try to understand the code, its not that complicated ;)

With this code you can pass expressions to ArrayInit
link to my youtube channel under my avatar!
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: NXC: can't pass expression to ArrayInit

Post 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.
muntoo
Posts: 834
Joined: 01 Oct 2010, 02:54
Location: Your Worst Nightmare
Contact:

Re: NXC: can't pass expression to ArrayInit

Post 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 #defines) I don't see what's wrong with using #defines. 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.)
Image

Commit to LEGO Mindstorms Robotics Stack Exchange:
bit.ly/MindstormsSE


Commit to LEGO Stack Exchange: bit.ly/Area51LEGOcommit
Locked

Who is online

Users browsing this forum: No registered users and 8 guests