NXC: concatening assignments with arrays: error!

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

NXC: concatening assignments with arrays: error!

Post by HaWe »

if I write

Code: Select all

buf=sum[j]=sum[j] + d2;
I get a compiler error (";" expected")

but this works:

Code: Select all

sum[j]=sum[j] + d2;
buf=sum[j];
Last edited by HaWe on 05 Feb 2011, 23:13, edited 1 time in total.
muntoo
Posts: 834
Joined: 01 Oct 2010, 02:54
Location: Your Worst Nightmare
Contact:

Re: NXC: concatening equations: error!

Post by muntoo »

doc-helmut wrote:

Code: Select all

buf=sum[j]=sum[j] + d2;
NXC doesn't support that yet.

Code: Select all

int line = 8;
for(int lol; lol = line; line--)
{
    TextOut(0, line*8, "lol", 0);
}
Will probably give you an error, for example.
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: concatening equations: error!

Post by HaWe »

I think you're wrong, muntoo.
It's legal C code, and NXC should indeed support that too.
Already since the falsly as "obsfucated" decried chess program, IIRC.
;)
this should work also:

Code: Select all

buf=sum[j]+=d2;
muntoo
Posts: 834
Joined: 01 Oct 2010, 02:54
Location: Your Worst Nightmare
Contact:

Re: NXC: concatening equations: error!

Post by muntoo »

doc-helmut wrote:It's legal C code, and NXC should indeed support that too.
I meant that NXC doesn't support it yet. I have nothing against ACDC. :)
Of course, I do have something against obfuscation (unless I'm trying to write obfuscated code on purpose).
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: concatening equations: error!

Post by HaWe »

no muntoo, it normally should.
The reason why I posted it of course is that I observed that it actually doesn't. Why else should I post it? it's a bug!
Your postings really don't help along.
What's that all about "obsfucation" with this issue? It's a simple right-to-left concatening of assignments!

Code: Select all

e=d=c=b=a;
a=(a>b?)c:d;
a=b=a>d;
a=(c<<d>>e);

On the other hand, this works fine:

Code: Select all

p=t=0;
SoundRecord[t]=SoundLevel=SensorValue(S2);
but NOT this:

Code: Select all

buf=sum[j]=sum[j] + d2;
buf=sum[j] += d2
why?
I guess it's an issue related to temp variables used for array types.
Last edited by HaWe on 05 Feb 2011, 22:55, edited 1 time in total.
spillerrec
Posts: 358
Joined: 01 Oct 2010, 06:37
Location: Denmark
Contact:

Re: NXC: concatening equations: error!

Post by spillerrec »

NXC does indeed support chained assignments, but as shown it appears it cannot understand the syntax correctly when arrays are included.
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: NXC: concatening equations: error!

Post by HaWe »

right, spiller, but why else do you think I posted this bug? ;)
look at my example of an another chained assignment with arrays, but that works fine:

Code: Select all

SoundRecord[t]=SoundLevel=SensorValue(S2);
I guess it's because of temporary vars internally used for calculating this part:

Code: Select all

array[x]=array[x]+d
array[x]+=d
and again:
it's a syntax error (parser or pre processor), not a run time error!
muntoo
Posts: 834
Joined: 01 Oct 2010, 02:54
Location: Your Worst Nightmare
Contact:

Re: NXC: concatening equations: error!

Post by muntoo »

OK, I get it now. :)
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: NXC: concatening assignments with arrays: error!

Post by spillerrec »

Helmut, the post was intended to muntoo, I didn't notice that you had explained it that clearly already.

I don't think it is related to temporary variables because this (which does not need any temporary variables) does not work either:

Code: Select all

bla = bla2[1] = bla3;
But mostly because of the type of error message. It thinks the code is wrong (though it isn't) and therefore doesn't even attempt to compile it. (When it cannot compile it correctly it usually ends up being some gibberish together with some NBC code. (Or doesn't even notice it as seen several times ; ) ))
My blog: http://spillerrec.dk/category/lego/
RICcreator, an alternative to nxtRICeditV2: http://riccreator.sourceforge.net/
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: NXC: concatening assignments with arrays: error!

Post by afanofosc »

Once upon a time NXC did not allow an assignment to be an expression (i.e., something that returns a value that could then be used by something else). Now it does in a lot of cases but not all cases. I probably will not spend a lot of time perfecting this since there are many, many, many, many ways you can work around this compiler limitation. Ditto for when += does or does not work. If you want to use a real C compiler you could try NXTOSEK. Before I get around to these kind of problems I will probably get around to implementing API functions for the Tetrix controllers. Please do not start holding your breath but if you have already started you should exhale and breathe normally!

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

Who is online

Users browsing this forum: No registered users and 0 guests