Page 10 of 25

Re: wishlist for NXC

Posted: 23 May 2011, 20:55
by HaWe
what about overloading functions?
All function-types-problems and different-number-of-parameters-problems could be resolved.

ok, I admit: this is not ANSI C 99 - but C++ like...
it might get us 1 step closer to ACDC++
;)

examples: printf could work with unlimited numbers and sorts of parameters, min/max the same, even arithmetic operators could be overloaded to work with complex numbers as well... :)

Re: wishlist for NXC

Posted: 24 May 2011, 23:42
by muntoo
Variable Arguments

By that, I mean that the arguments will be able to be passed as an array (as opposed to the traditional pointer).

Example:

Code: Select all

long sum(long list, ...)
{
    long out = 0;
    for(unsigned long i = 0; i < ArrayLen(list); ++i)
        out += list[i];
    return(out);
}

NumOut(0, 0, sum(1, 2, 3, 4));
// Is equivalent to:
NumOut(0, 0, 1 + 2 + 3 + 4);
In other words, we should be able to code our own ArrayBuild().

Re: wishlist for NXC

Posted: 25 May 2011, 06:33
by HaWe
that's not the issue of my wish.
My wish was about a general way to overload functions and operators with multiple counts and sorts of parameters which work possibly different depending on the special case.
Some extreme examples:

float foo(int i, float f) { return (i*f);}

float foo(int i, int j, float f) {return ((i+j)/f);}

int foo (int i, int j, int h) {return(i+j+h);}

void foo(float &f){f=sin(f);}

float f[2], g[2], h[2];
h=f *g; // * overloaded by complex multiplication: <=> h[0]=f[0]*g[0] - f[1]*g[1]; h[1]=f[0]*g[1] + f[1]*g[0];

Re: wishlist for NXC

Posted: 25 May 2011, 08:53
by mightor
Doc,

John has already expressed his intention to implement function overloads a while back. I bugged him about it incessantly at LEGO World last year so I can port my driver suite to NXC :)

- Xander

Re: wishlist for NXC

Posted: 28 May 2011, 11:27
by HaWe
really?
:P
when? (not when you bugged him but...)
;)

Re: wishlist for NXC

Posted: 29 May 2011, 21:43
by muntoo
Explicit casting

Code: Select all

int pi = int(3.14);
// pi = 3;

float e = (float)2;
// e = 2.0;

Re: wishlist for NXC

Posted: 30 May 2011, 07:06
by HaWe
muntoo,
it's a typo probably:

int pi=(int)3.14;

or:

Code: Select all

float pi=3.1415;
int pii;
pii=(int)pi;
for type conversion the new type is included in parenthesis, not the value ;)

but I wish to have that, too!

Re: wishlist for NXC

Posted: 31 May 2011, 00:41
by muntoo
Actually, int(3.14) is legal. (Functional notation. I think it's C++ only...?)

EDIT: More here.

Re: wishlist for NXC

Posted: 01 Jun 2011, 16:23
by HaWe
correct, it's exactly as you said by yourself, function type cast is C++, not C
;)

Re: wishlist for NXC

Posted: 14 Jun 2011, 19:43
by HaWe
is there a chance to speed up the enh FW in relation to the std FW ?