View unanswered posts | View active topics It is currently Sat Apr 19, 2014 9:22 am






Reply to topic  [ 10 posts ] 
v1.10 crashes repeatably 
Author Message
Rookie

Joined: Thu Apr 10, 2008 11:51 pm
Posts: 2
Post 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:
//*!!Sensor,    S1,                 MISO, sensorDigitalIn,      ,                !!*//
//*!!                                                                            !!*//
//*!!Start automatically generated configuration code.                           !!*//
const tSensors MISO                 = (tSensors) S1;   //sensorDigitalIn    //*!!!!*//
//*!!CLICK to edit 'wizard' created sensor & motor configuration.                !!*//

byte rec( byte prev );

void main()
{
   byte x = 4;

   if( MISO )
      x = 1;

   x = rec( 5 );

}

byte rec( byte prev )
{
   if( prev == 0 )
      return 1;
   else
      return ( prev + rec( prev - 1 ) );
}
[/code]


Fri Apr 11, 2008 12:01 am
Profile
Rookie

Joined: Sat Apr 19, 2008 12:55 pm
Posts: 4
Location: Netherlands
Post Re: v1.10 crashes repeatably
foolsday wrote:
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:

* snip *



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
Profile
Rookie

Joined: Sat Apr 19, 2008 11:51 am
Posts: 43
Post 
hello,
are recursions possible in NXC?


Sat Apr 19, 2008 2:06 pm
Profile
Rookie

Joined: Sat Apr 19, 2008 12:55 pm
Posts: 4
Location: Netherlands
Post 
spaceballs wrote:
hello,
are recursions possible in NXC?


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
Profile
Rookie

Joined: Sat Apr 19, 2008 11:51 am
Posts: 43
Post 
mtsinot wrote:
...you can possibly enter a pointer to that function in a table and call it indirectly.

hi,
how is this to be done?


Wed Apr 23, 2008 12:10 pm
Profile
Rookie

Joined: Sat Apr 19, 2008 12:55 pm
Posts: 4
Location: Netherlands
Post 
spaceballs wrote:
mtsinot wrote:
...you can possibly enter a pointer to that function in a table and call it indirectly.

hi,
how is this to be done?


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
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post 
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
Profile
Rookie

Joined: Sat Apr 19, 2008 12:55 pm
Posts: 4
Location: Netherlands
Post 
Ford Prefect wrote:
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!


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
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post 
mtsinot wrote:
It seems that if recursion is really wanted, the OS architecture needs serious rethinking.


to this point I fully agree :wink:

_________________
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
Profile
Rookie

Joined: Sat Dec 22, 2007 7:02 pm
Posts: 7
Post 
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
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 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

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.