It appears the following statements add incorrectly:
unsigned long aulHold[2];
unsigned int uiT;
aulHold[ucChan] = aulHold[ucChan] + uiT;
or
aulHold[ucChan] += uiT;
This was tested with both operands being zero, but it may have problems with other values.
It appears to be a conversion problem. Casting uiT to an unsigned long will appear to solve the problem for operands that are zero, but will not add correctly. Changing uiT to an unsigned long appears to fix the problem.
This problem does not appear to occur (in at least some cases) when the unsigned long variable is not an array (i.e. a simple variable). I have not tested when the variable is accessed through a pointer or in a structure.
If this is code dependant, please let me know and I will send sample code.
Array arithmetic conversion addition bug
Array arithmetic conversion addition bug
Last edited by Darryl on 01 Apr 2009 23:12, edited 1 time in total.
Re: Array arithmetic conversion addition bug
Please post or send sample code to rajkovic@mikroe.comDarryl wrote:It appears the following statements add incorrectly:
unsigned long aulHold[2];
unsigned int uiT;
aulHold[ucChan] = aulHold[ucChan] + uiT;
or
aulHold[ucChan] += uiT;
This was tested with both operands being zero, but it may have problems with other values.
It appears to be a conversion problem as either changing uiT to an unsigned long or casting it to an unsigned long fix the problem.
This problem does not appear to occur (in at least some cases) when the unsigned long variable is not an array (i.e. a simple variable). I have not tested when the variable is accessed through a pointer or in a structure.
If this is code dependant, please let me know and I will send sample code.
together with description what is the problem.
We had not been able to reproduce problem (is it p16 or p18)