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:

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

spaceballs

Rookie

Joined: Sat Apr 19, 2008 11:51 amPosts: 43

hello,
are recursions possible in NXC?

Sat Apr 19, 2008 2:06 pm

mtsinot

Rookie

Joined: Sat Apr 19, 2008 12:55 pmPosts: 4Location: Netherlands

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

spaceballs

Rookie

Joined: Sat Apr 19, 2008 11:51 amPosts: 43

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

mtsinot

Rookie

Joined: Sat Apr 19, 2008 12:55 pmPosts: 4Location: Netherlands

spaceballs wrote:

mtsinot wrote:

...you can possibly enter a pointer to that function in a table and call it indirectly.

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 pmPosts: 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!

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

Ford Prefect

Guru

Joined: Sat Mar 01, 2008 12:52 pmPosts: 1030

mtsinot wrote:

It seems that if recursion is really wanted, the OS architecture needs serious rethinking.

Who is online

Users browsing this forum: No registered users and 2 guests

You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum