Pages: [1]   Go Down
Author Topic: ArduinoISP, suggestion to improve portability  (Read 2306 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
God Member
*****
Karma: 0
Posts: 594
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ArduinoISP.pde provided with Arduino 0022, line 364

Code:
int length = 256 * getch() + getch();

With the GNU compiler, if 0x00 is received first and then 0x80 is received second, then this evaluates to

Code:
int length = 256 * 0x00 + 0x80;

and the result of "length" is 128 as expected

However, if this code is ported to another compiler, the following happens

Code:
int length = 256 * 0x80 + 0x00;

the result of "length" is 0x8000, which is not the expected result. This has caused a port of the ArduinoISP code to fail by running the for loop on line 343 for longer than what avrdude specified, causing a timeout.

please see http://en.wikipedia.org/wiki/Sequence_point about the nature of the problem
Quote
Consider two functions f() and g(). In C and C++, the + operator is not a sequence point, and therefore in the expression f()+g() it is possible that either f() or g() will be executed first.

Due to this, I plead that the next release would use something like

Code:
unsigned char higherBits = getch();
unsigned char lowerBits = getch();
int length = 256 * higherBits + lowerBits;

There are several locations where this change needs to be made, the one I pointed out is only one such location.
Logged

Freelance engineer, consultant, contractor. Graduated from UW in 2013.

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 124
Posts: 6652
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You should submit this as an issue at http://code.google.com/p/arduino/
Logged

0
Offline Offline
God Member
*****
Karma: 0
Posts: 594
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

bah, I don't think anybody watches the issue list, there are 266 issues still open :-/
Logged

Freelance engineer, consultant, contractor. Graduated from UW in 2013.

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 124
Posts: 6652
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The beauty of the issue list is that your issue will stay there until addressed, even if no one is paying any attention.  Whereas if you just report it in the forums, it falls off of everyone's radar screen and becomes forgotten...

Right now, there's a lot of focus on the changes they want to get made for the 1.0 release.

Issues get fixed faster with complete patchable diffs attached...
Logged

Pages: [1]   Go Up
Jump to: