Page 1 of 2

NXC: concatening assignments with arrays: error!

Posted: 05 Feb 2011, 17:22
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];

Re: NXC: concatening equations: error!

Posted: 05 Feb 2011, 19:41
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.

Re: NXC: concatening equations: error!

Posted: 05 Feb 2011, 19:50
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;

Re: NXC: concatening equations: error!

Posted: 05 Feb 2011, 22:25
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).

Re: NXC: concatening equations: error!

Posted: 05 Feb 2011, 22:45
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.

Re: NXC: concatening equations: error!

Posted: 05 Feb 2011, 22:54
by spillerrec
NXC does indeed support chained assignments, but as shown it appears it cannot understand the syntax correctly when arrays are included.

Re: NXC: concatening equations: error!

Posted: 05 Feb 2011, 22:58
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!

Re: NXC: concatening equations: error!

Posted: 05 Feb 2011, 23:13
by muntoo
OK, I get it now. :)

Re: NXC: concatening assignments with arrays: error!

Posted: 05 Feb 2011, 23:41
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 ; ) ))

Re: NXC: concatening assignments with arrays: error!

Posted: 07 Feb 2011, 21:34
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