Page 14 of 25
Re: wishlist for NXC
Posted: 11 Jul 2011, 09:26
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?)
Re: wishlist for NXC
Posted: 11 Jul 2011, 17:41
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...)
Re: wishlist for NXC
Posted: 11 Jul 2011, 17:55
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
Re: wishlist for NXC
Posted: 11 Jul 2011, 18:06
by muntoo
Read.
Standards.
We're getting OT...
Re: wishlist for NXC
Posted: 11 Jul 2011, 18:59
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"
Re: wishlist for NXC
Posted: 11 Jul 2011, 19:59
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:
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.)
Re: wishlist for NXC
Posted: 11 Jul 2011, 20:07
by HaWe
thx, now I understand.
(Before it was incomprehensible to me.)
Re: wishlist for NXC
Posted: 12 Jul 2011, 14:53
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
Re: wishlist for NXC
Posted: 22 Jul 2011, 22:46
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
}
Re: wishlist for NXC
Posted: 23 Jul 2011, 00:10
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.