Page 12 of 25

Re: wishlist for NXC

Posted: 19 Jun 2011, 15:20
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

Re: wishlist for NXC

Posted: 19 Jun 2011, 18:29
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! ;))

Re: wishlist for NXC

Posted: 19 Jun 2011, 20:37
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

Re: wishlist for NXC

Posted: 22 Jun 2011, 20:30
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)

Re: wishlist for NXC

Posted: 24 Jun 2011, 00:04
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() { }

Re: wishlist for NXC

Posted: 24 Jun 2011, 06:32
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;
    }


Re: wishlist for NXC

Posted: 24 Jun 2011, 06:37
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;

Re: wishlist for NXC

Posted: 25 Jun 2011, 14:46
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)

Re: wishlist for NXC

Posted: 05 Jul 2011, 09:34
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)

Re: wishlist for NXC

Posted: 06 Jul 2011, 01:41
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