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 »

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... :)
muntoo
Posts: 834
Joined: 01 Oct 2010, 02:54
Location: Your Worst Nightmare
Contact:

Re: wishlist for NXC

Post 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().
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 »

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];
mightor
Site Admin
Posts: 1079
Joined: 25 Sep 2010, 15:02
Location: Rotterdam, Netherlands
Contact:

Re: wishlist for NXC

Post 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
| My Blog: I'd Rather Be Building Robots (http://botbench.com)
| RobotC 3rd Party Driver Suite: (http://rdpartyrobotcdr.sourceforge.net)
| Some people, when confronted with a problem, think, "I know, I'll use threads,"
| and then two they hav erpoblesms. (@nedbat)
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: wishlist for NXC

Post by HaWe »

really?
:P
when? (not when you bugged him but...)
;)
muntoo
Posts: 834
Joined: 01 Oct 2010, 02:54
Location: Your Worst Nightmare
Contact:

Re: wishlist for NXC

Post by muntoo »

Explicit casting

Code: Select all

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

float e = (float)2;
// e = 2.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 »

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!
muntoo
Posts: 834
Joined: 01 Oct 2010, 02:54
Location: Your Worst Nightmare
Contact:

Re: wishlist for NXC

Post by muntoo »

Actually, int(3.14) is legal. (Functional notation. I think it's C++ only...?)

EDIT: More here.
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 »

correct, it's exactly as you said by yourself, function type cast is C++, not C
;)
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: wishlist for NXC

Post by HaWe »

is there a chance to speed up the enh FW in relation to the std FW ?
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests