wishlist for NXC

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: wishlist for NXC

Post by HaWe »

I'm inclined to leave things as they are in NXC wrt uninitialized local variables.
it seems to be initialized to 0 though:

Code: Select all

void testFunction() {
  static int i;
  ++i;
  NumOut(0,0,i);
}

task main() {
  testFunction(); // ...
  testFunction(); // ...
  testFunction(); // prints 3
  while(1);
}
after restarting this program several times, it always shows "3" . So "static i" seems to be initialized to 0 for every new run.
CMIIW, but if not re-initialized to 0 it should keep the last value in memory after program abort and should increase i by 3 in the end for every new program run (that's what C is supposed to do ... or not?)
spillerrec
Posts: 358
Joined: 01 Oct 2010, 06:37
Location: Denmark
Contact:

Re: wishlist for NXC

Post by spillerrec »

AFAIK, it is not possible to not initialize variables to something at program start. It must either be a user-defined value or NULL. Uninitialized variables in NXC will therefore be initiated to NULL.
I haven't read the C specification but I would imagine it says that the behavior of uninitialized variables are undefined. Does anyone know? (To be honest I actually don't really care that much about how NXC handles this or how it is supposed to behave in C...)
My blog: http://spillerrec.dk/category/lego/
RICcreator, an alternative to nxtRICeditV2: http://riccreator.sourceforge.net/
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: wishlist for NXC

Post by HaWe »

well, I don't care either, I just want to know - and John's post in this context
I'm inclined to leave things as they are in NXC wrt uninitialized local variables.
as I understand it, there actually are things like uninitialized local variables
though but my program example shows, that there aren't
muntoo
Posts: 834
Joined: 01 Oct 2010, 02:54
Location: Your Worst Nightmare
Contact:

Re: wishlist for NXC

Post by muntoo »

Read.
Standards.

We're getting OT...
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: wishlist for NXC

Post by HaWe »

muntoo, you misunderstand me.
I didn't want to know what C does,
I wanted to know what Johnt meant saying "leaving... uninitialized local variables"
muntoo
Posts: 834
Joined: 01 Oct 2010, 02:54
Location: Your Worst Nightmare
Contact:

Re: wishlist for NXC

Post by muntoo »

doc-helmut wrote:I wanted to know what Johnt meant saying "leaving... uninitialized local variables"
It means John wants:

Code: Select all

task main() {
    int x;
    printf("%d", x); // prints 0
}
He doesn't want:

Code: Select all

    printf("%d", x); // prints 15394 (i.e. garbage)
Or:

Code: Select all

    printf("%d", x); // CRASH!
Same applies to all other ways to declare x: globally, etc. (I don't know about arrays, but I presume that it'll set everything to 0.)
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: wishlist for NXC

Post by HaWe »

thx, now I understand.
(Before it was incomprehensible to me.)
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: wishlist for NXC

Post by afanofosc »

All I meant was that I would not change NXC to explicitly initialize local variables that lack a user-specified initial value to zero at runtime. As has been pointed out, all along NXC has been generating variable declarations for variables that you do not explicitly initialize in your code in a manner that initializes them to zero when the RXE begins execution. I will leave this unchanged.

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
nxtboyiii
Posts: 366
Joined: 02 Oct 2010, 07:08
Location: Everywhere

Re: wishlist for NXC

Post by nxtboyiii »

I would like to have a function to rotate an ric file.
I would also like to be able to rotate polygons. Like this:

void RotatePoly(LocationType &points[], int degrees)
{
//Rotate it
}
Thanks, and have a nice day,
nxtboy III

programnxt.com
muntoo
Posts: 834
Joined: 01 Oct 2010, 02:54
Location: Your Worst Nightmare
Contact:

Re: wishlist for NXC

Post by muntoo »

nxtboyiii wrote:I would like to have a function to rotate an ric file.
Or the ability to efficiently read/write to the display screen memory. (We could apply our own transforms by developing our own libraries.)

The rotate polygons should be easy enough, though - I suggest you create a separate thread.
Image

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


Commit to LEGO Stack Exchange: bit.ly/Area51LEGOcommit
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests