NXC: can't pass expression to ArrayInit

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

NXC: can't pass expression to ArrayInit

Post by HaWe »

NXC: can't pass expression to ArrayInit

This doesn't work:

Code: Select all

  int i=0, S, R;
  ArrayInit(C, 0, R*S);
This works:

Code: Select all

  int i=0, S, R;
  int dim=R*S;
  ArrayInit(C, 0, dim);
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: NXC: can't pass expression to ArrayInit

Post by afanofosc »

Doc, ArrayInit along with many other NXC API functions cannot take NXC expressions since they are simply #define macros that emit an NBC asm block. I will try to improve the documentation to make this clear.

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: NXC: can't pass expression to ArrayInit

Post by HaWe »

what a pity!
(for the wish list: every function (edit: AND expression) should be allowed to get expressions (variables, functions) passed to it!)
Last edited by HaWe on 17 Jul 2011, 12:58, edited 1 time in total.
muntoo
Posts: 834
Joined: 01 Oct 2010, 02:54
Location: Your Worst Nightmare
Contact:

Re: NXC: can't pass expression to ArrayInit

Post by muntoo »

doc-helmut wrote:(for the wish list: every function should be allowed to get expressions (variables, functions) passed to it!)
Yeah, but then we lose the awesome optimizations. If the NBC intermediate code optimizer was improved, we could have inline NXC API functions instead.
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: NXC: can't pass expression to ArrayInit

Post by HaWe »

Maybe we could drop NBC some day at all because NXC can generate byte code directly? :))
And will be able to program awesome optimizations even using C code by our own? :))))
(let NXC become such a C compiler, not a code interpreter for NBC!)
Last edited by HaWe on 16 Jul 2011, 14:48, edited 1 time in total.
linusa
Posts: 228
Joined: 16 Oct 2010, 11:44
Location: Aachen, Germany
Contact:

Re: NXC: can't pass expression to ArrayInit

Post by linusa »

doc-helmut wrote: (let NXC become a compiler
Your wish has been granted! NXC has become a compiler.
RWTH - Mindstorms NXT Toolbox for MATLAB
state of the art in nxt remote control programming
http://www.mindstorms.rwth-aachen.de
MotorControl now also in Python, .net, and Mathematica
muntoo
Posts: 834
Joined: 01 Oct 2010, 02:54
Location: Your Worst Nightmare
Contact:

Re: NXC: can't pass expression to ArrayInit

Post by muntoo »

First of all: NXC is not a "code interpreter" for NBC.
doc-helmut wrote:Maybe we could drop NBC some day at all because NXC can generate byte code directly? :)
Erm... Any good compiler (most likely [almost] any compiler) will generate an intermediate code representation - like NBC.

Not technically correct:
NXC->Lexer->Syntax Analyzer->Semantic Analyzer->Parser->Intermediate Optimization->Intermediate Representation (NBC)->Byte code (RXE)->Byte code optimization?

Simpler version:
NXC->NBC->RXE

It's a hell lot easier to fix compiler bugs, maintain, optimize, etc. As a bonus, you can look at the NBC code too, and see what the compiler's thinking! :D
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: NXC: can't pass expression to ArrayInit

Post by HaWe »

well, though NBC is actually the byte code compiler, not NXC, while NXC appears to me more or less to be a code parser to NBC (as far as I can recognize it ( - parser; interpreter was surely the wrong word - )), and many of NXC keywords seem to be wraps around NBC code, we're getting OT.
To me it would be sufficient for the 1st step if
every function (edit: AND expression!) should be allowed to get expressions (variables, functions) passed to it
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: NXC: can't pass expression to ArrayInit

Post by afanofosc »

The API library is not the compiler. You are welcome to write function wrappers around NXC API library routines that do not have the behavior or functionality that you are looking for.

The primary reason why many API functions are #define macros that emit asm blocks is because this allows for what the help refers to as "variant" arguments. Function overloading is not coming any time soon since it is EXTREMELY HARD for me to figure out how to support it. The #define macros give you that ability and result in faster code with the limitation that you can't pass NXC expressions into them.

FYI, especially of late you are not making me eager to help you or to implement items from your NXC wish list.

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: NXC: can't pass expression to ArrayInit

Post by HaWe »

#defines do not help if I want to pass a A[] instead of a A[][] to a function, because they are calculating internally by different formulas (e.g., for a[k] x B[k][n] a[k] has to be transformed to a[k]Tbefore, the same it's for a[k] x b[k].

BTW, what means "especially of late you are not making me eager to help you or to implement items from your NXC wish list"? why am I late?
Locked

Who is online

Users browsing this forum: No registered users and 4 guests