|
Page 1 of 1
|
[ 10 posts ] |
|
Author |
Message |
foolsday
Rookie
Joined: Thu Apr 10, 2008 11:51 pm Posts: 2
|
 v1.10 crashes repeatably
Hello all,
I recently downloaded the trial version because I'm about to kick off a large project and I thought I'd evaluate RobotC before I get too invested in NXC. However, I started writing a sample program and stumbled upon a sequence that causes the ide to crash swiftly and repeatedly until I rename the file. Obviously my first impression of the compiler/ide isn't very favorable. The offensive code is:
[/code]
|
Fri Apr 11, 2008 12:01 am |
|
 |
mtsinot
Rookie
Joined: Sat Apr 19, 2008 12:55 pm Posts: 4 Location: Netherlands
|
 Re: v1.10 crashes repeatably
The cause of the crash is the recursive function call in the rec function. Although it is legal C, recursive code is something you usually want to avoid in embedded code (which this essentially is). Embedded processors often have a very small stack, so there is no room for stack-consuming recursive functions. Rewrite it to a nonrecursive version and you will be fine. Of course, it is not very nice for the compiler to crash on this. (If I am to guess about the root cause of the crash, I would suspect that the compiler tries to place variables in the target memory and on the recursive function call exhausts its stack or something. We have an assembler which shows the same behaviour when trying to do something recursive).
A second error is that main must always be a task. Rename "void main" to "task main".
|
Sat Apr 19, 2008 1:13 pm |
|
 |
spaceballs
Rookie
Joined: Sat Apr 19, 2008 11:51 am Posts: 43
|
hello,
are recursions possible in NXC?
|
Sat Apr 19, 2008 2:06 pm |
|
 |
mtsinot
Rookie
Joined: Sat Apr 19, 2008 12:55 pm Posts: 4 Location: Netherlands
|
To circumvent the bug described above you can possibly enter a pointer to that function in a table and call it indirectly. Beware that local variables most likely are declared static, so reuse will overwrite an earlier instance of the function call: functions are not reentrant. You will have to do some work to get it working for you.
|
Wed Apr 23, 2008 10:02 am |
|
 |
spaceballs
Rookie
Joined: Sat Apr 19, 2008 11:51 am Posts: 43
|
hi,
how is this to be done?
|
Wed Apr 23, 2008 12:10 pm |
|
 |
mtsinot
Rookie
Joined: Sat Apr 19, 2008 12:55 pm Posts: 4 Location: Netherlands
|
It should have been done by doing something like:
void recursive_func (int);
typedef void (*func_t)(int);
func_t f = recursive_func;
(for a function taking an int as parameter)
and then later call f(value).
However, it appears that RobotC does not allow this construction. So it is not possible (at least not in any way I know of).
But, as said, you usually want to avoid recursion in embedded code anyway.
|
Sat Apr 26, 2008 3:36 am |
|
 |
Ford Prefect
Guru
Joined: Sat Mar 01, 2008 12:52 pm Posts: 1030
|
the NXT is not a tiny embedded system but has a processor comparable to Motorola/Apple 68000 or Intel/IBM 8086/80286.
not to support recursions for such a platform by a programming language which is advertised as "real C" is really poor, and this needs to be implemented!
_________________ regards, HaWe aka Ford #define S sqrt(t+2*i*i)<2 #define F(a,b) for(a=0;a<b;++a) float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}
|
Sat Apr 26, 2008 4:27 am |
|
 |
mtsinot
Rookie
Joined: Sat Apr 19, 2008 12:55 pm Posts: 4 Location: Netherlands
|
That might be, but as far as I can see, it appears to be implemented this way. The local variables of a procedure appear as global variables if you open the debug window. The compiler can possibly overlay variables in procedures if they do not run at the same time, but in this architecture, it cannot do recursion (and it even crashes when attempting to do so). It seems that if recursion is really wanted, the OS architecture needs serious rethinking.
BTW, comparing to modern standards, although the NXT has an ARM, it IS tiny, when even small systems have memories measured in the megabytes! I can't even obtain a memory smaller than 2 Mbit for a simple chip test program.
|
Sat Apr 26, 2008 4:11 pm |
|
 |
Ford Prefect
Guru
Joined: Sat Mar 01, 2008 12:52 pm Posts: 1030
|
to this point I fully agree 
_________________ regards, HaWe aka Ford #define S sqrt(t+2*i*i)<2 #define F(a,b) for(a=0;a<b;++a) float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}
|
Sat Apr 26, 2008 6:51 pm |
|
 |
EricPascual
Rookie
Joined: Sat Dec 22, 2007 7:02 pm Posts: 7
|
Is the original problem really related to the recursion problem ?
The opening post says that the IDE crashes, not the NTX brick. If the problem was what is mentioned in replies, a brick crash would have been experienced, not an IDE one.
|
Sat May 31, 2008 3:04 am |
|
|
|
Page 1 of 1
|
[ 10 posts ] |
|
Who is online |
Users browsing this forum: No registered users and 2 guests |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum
|
|