View previous topic :: View next topic |
Author |
Message |
lecutus
Joined: 12 Aug 2009 Posts: 40
|
Is this right? |
Posted: Thu Dec 10, 2009 9:25 am |
|
|
Is this right? Notice the text in bold letterring the " cprm= cprm = "
if (rx_ad==44) {crpm=crpm=make16(buffer[2],buffer[1]); //store req spd buffer
I usually program in various forms of C, so this caught me off guard. Is there any esoteric reason exclusive to this compiler, why this is?
Or is this a standard misteak?
This is not my code. I'm in the middle of a rewrite, taking only the parts that work.
Thanks
L. |
|
|
mkuang
Joined: 14 Dec 2007 Posts: 257
|
|
Posted: Thu Dec 10, 2009 9:40 am |
|
|
That looks like a bug, but I am not a C expert, maybe it is a shortcut for writing something, but it does look dubious. |
|
|
Ttelmah Guest
|
|
Posted: Thu Dec 10, 2009 9:40 am |
|
|
No reason.
Won't do any harm (in C, you can perform multiple assignments on a single line, and they propogate right to left). The optimiser will probably get rid of the duplicate, but it is almost certainly just a typing error.
Best Wishes |
|
|
lecutus
Joined: 12 Aug 2009 Posts: 40
|
|
Posted: Thu Dec 10, 2009 10:35 am |
|
|
I guess in retrospect it doesn't make sense to send an amount to a variable and then to the same variable.
For the record the optimiser didn't get rid of it. This code has been worked on quite a bit. For some reason it's considered a legal statement.
Thanks for the answers.
L. |
|
|
Ttelmah Guest
|
|
Posted: Thu Dec 10, 2009 11:29 am |
|
|
It is perfectly legal in C. If you have a number of variables, you can have:
a=b=c=d
and the value of 'd' will propogate right to left (as I originally pointed out). So it won't cause a problem, but will just involve moving the data twice. The fact that the second move involves moving the data from itself to itself, is what I rather hoped the optimiser might remove. The later CCS compilers normally do remove things like this, but presumably here, the code is so 'explicit', that the optimiser doesn't get rid of it....
Best Wishes |
|
|
lecutus
Joined: 12 Aug 2009 Posts: 40
|
|
Posted: Thu Dec 10, 2009 12:51 pm |
|
|
Thanks T.
That little trick, a=b=c=d, may come in handy some day.
L. |
|
|
|