wishlist for NXC

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
spillerrec
Posts: 358
Joined: 01 Oct 2010, 06:37
Location: Denmark
Contact:

Re: wishlist for NXC

Post by spillerrec »

muntoo wrote:That's what static is for. (I asked for that a little while ago.)
You can't apply the static keyword on the temporary variables...

EDIT:
Here you have it:

Code: Select all

#define static ;

void foo(){
  static int counter;
  NumOut(0,0, counter );
  counter++;
}

task main(){
  while( true ){
    foo();
    Wait( 500 );
  }
}
Well, almost... : P
My blog: http://spillerrec.dk/category/lego/
RICcreator, an alternative to nxtRICeditV2: http://riccreator.sourceforge.net/
muntoo
Posts: 834
Joined: 01 Oct 2010, 02:54
Location: Your Worst Nightmare
Contact:

Re: wishlist for NXC

Post by muntoo »

spillerrec wrote:You can't apply the static keyword on the temporary variables...
Then the "staticness" should be inherited by the "temporary" variables...? Besides, "performance" won't decrease by any distinguishable amount - the memory will be reallocated anyways when you reuse the "temporary" variables.
spillerrec wrote:Here you have it:

Code: Select all

static int counter;
Well, almost... : P
Doesn't work if I use static int counter = 1; ++counter; (It always equals two for some reason! ;))
Image

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


Commit to LEGO Stack Exchange: bit.ly/Area51LEGOcommit
spillerrec
Posts: 358
Joined: 01 Oct 2010, 06:37
Location: Denmark
Contact:

Re: wishlist for NXC

Post by spillerrec »

The compiler creates quite a bit of those temporary strings and similarly it would need to create just as many ArrayInit statements plus for all the manually declared strings. It can easily end up being quite a bit, just look how strcat adds 3 strings that will not be reused for other string operations...

I will never get satisfied anyway, I should just get used to write NBC instead...


[quote=muntoo]Doesn't work if I use static int counter = 1; ++counter; (It always equals two for some reason! )[/quote]You also want initialized static variables? You sure are demanding! : P
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 »

John, could you pls change the weird sensor functions?
that is horrible and confusing and weird.
Please sacrifice those weird and odd definitions.

Most of all I would like to have a standard function
void InitSensor(port, SensorType) (or SensorInit) where SensorType is ANY type (analog, i2cLS, i2cHS and RS485) (i2cHS for future like implemented by RobotC).

No more SensorTouch, SensorLowSpeed, SensorTemperature, SensorLightActive and all that. You may transfer them to kind of sensor types, not sensor initializing functions.

Then I'd wish to have
SensorValue(port, &value[]) which returns one or more dimensional sensor values, if not specified then the real raw values like the former SensorRaw() (0-1023)

Then I wish to have a
SensorUnit(port)
which may specify specific units like percent, inverse raw( 1023-0), touch, pulse, edge, normalized or scaled (what ever the latter 2 might be - i'm not supposed to use them EVER) .

That would make the usage VERY much more transparent and logical.

I know that this is VERY much non-Lego-like but very much comfortable for users for the future (legacy functions could be kept unducumented until extincted some day)
muntoo
Posts: 834
Joined: 01 Oct 2010, 02:54
Location: Your Worst Nightmare
Contact:

Re: wishlist for NXC

Post by muntoo »

Multiple function prototypes

It's legal C++, as far as I can tell.

Could we have the ability to declare [the same] prototypes multiple times in a row? This would make managing large "projects" a lot easier.

Code: Select all

void foo();
void foo();
void foo();

void foo() { }
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,
here's an example of how to use static in a subroutine for local variables. I'd appreciate if we had this, (mun)too: ;)

Code: Select all

    unsigned TT800(void) {
      const int N = 25;
      const int M = 7;
      const unsigned A[2] = { 0, 0x8ebfd028 };

      static unsigned y[25];
      static int index = N+1;

      if (index >= N) {
        int k;
        if (index > N) {
           unsigned r = 9, s = 3402;
           for (k=0 ; k<N ; ++k) {
             r = 509845221 * r + 3;
             s *= s + 1;
             y[k] = s + (r >> 10);
           }
        }
        for (k=0 ; k<N-M ; ++k)
           y[k] = y[k+M] ^ (y[k] >> 1) ^ A[y[k] & 1];
        for (; k<N ; ++k)
           y[k] = y[k+(M-N)] ^ (y[k] >> 1) ^ A[y[k] & 1];
        index = 0;
      }

      unsigned e = y[index++];
      e ^= (e << 7) & 0x2b5b2500;
      e ^= (e << 15) & 0xdb8b0000;
      e ^= (e >> 16);
      return e;
    }

HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: wishlist for NXC

Post by HaWe »

another issue:
global variable names should be modified by the NBC preprocessor (or however it is called) to get an underline NBC prefix (or postfix) _
because there are compiler issues with a global NXC variable e.g. called
int index;
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: wishlist for NXC

Post by HaWe »

IMHO the results of array statistics "mean" and "standard deviation" should be calculated always as floats independently from the value type of the samples
(if one wants to have them as ints one may round or truncate them)
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: wishlist for NXC

Post by HaWe »

I would appreciate to have a more efficient memory management concerning local variables passed to functions by reference.
(Having pointers would be very efficient)
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: wishlist for NXC

Post by afanofosc »

doc-helmut wrote:I would appreciate to have a more efficient memory management concerning local variables passed to functions by reference.
(Having pointers would be very efficient)
When you have added support for pointers/references in the NXT firmware I will begin the arduous task of supporting that new variable type in NXC. I am not planning at all to drive myself crazy trying to make those kind of firmware changes.

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
Post Reply

Who is online

Users browsing this forum: No registered users and 19 guests