View previous topic :: View next topic |
Author |
Message |
erik.wallebom
Joined: 30 Jan 2010 Posts: 2 Location: Sweden
|
Comparing int1 with float. Different results. Compiler bug? |
Posted: Sat Jan 30, 2010 12:17 pm |
|
|
Spent lots of hours today figuring out why a project of mine does not work as should. I have now isolated the problem code. Please take a look, thanks.
The difference between the IF statements is [i] instead of [0]. Since i=0 there should not be a difference.
Also if I change diffvalue to a int8 both IF statements outputs FALSE (which is what I expect).
Why this behaviour with int1 and using [i]? Is this a known problem?
Code: |
#include "include.h"
//RS-232 setup
#use rs232(baud=115200, xmit=PIN_C6, rcv=PIN_C7, PARITY=N, BITS=8, STOP=1)
//----Main----------------------------------------------------------------------
void main()
{
//----Setup the PIC----------------------------------------------------------
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF|ADC_TAD_MUL_0);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_2|RTCC_8_BIT);
//setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,255,1);
setup_timer_3(T3_DISABLED);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
//setup_oscillator(OSC_8MHZ|OSC_TIMER1|OSC_31250|OSC_PLL_OFF);
setup_oscillator(OSC_32MHZ|OSC_TIMER1|OSC_31250|OSC_PLL_OFF);
enable_interrupts(INT_TIMER0);
//disable_interrupts(GLOBAL);
float b=0;
float a=0;
float value[1]=0;
int1 diffvalue[1]=0;
int8 i=0;
//----Start main loop--------------------------------------------------------
for(;;)
{
putc(27); //Escape
printf("[0;0H"); //Home
printf("%g %g %u %g %u \n\r",a,b,i,value[i],diffvalue[i]);
if(value[0]!=diffvalue[0]) //This = FALSE = Correct!
{
a=a+1;
}
if(value[i]!=diffvalue[i]) //This = TRUE = Wrong!
{
b=b+1;
}
}
}
|
|
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
Compiler bug! |
Posted: Sat Jan 30, 2010 4:03 pm |
|
|
You didn't tell, which target you are using, I assumed PCH and could reproduce the problem with V4.104 and V4.099.
You possibly already found out, that the problem is with arrays of int1. The CCS C V4 manual tells generally:
Quote: | Arrays of bits (INT1) in RAM are now supported. |
That's partly true, however the int1 to float conversion is apparently not working correctly with array elements.
The compiler is using the int16 to float conversion function, but forgets to clear the high byte. The problem also
occurs when assigning an int1[] array element to a float variable. You may want to file a bug report to CCS.
I found a workaround, however.
Code: | if(value[i]!=(int8)diffvalue[i]) // seems to work correctly |
|
|
|
erik.wallebom
Joined: 30 Jan 2010 Posts: 2 Location: Sweden
|
|
Posted: Sat Jan 30, 2010 7:04 pm |
|
|
Yes, using PCH v4.103.
I have now filed a report to support@ccsinfo.com.
I will avoid int1 for now. Using int8 in the code does not generate the error.
Thanks. |
|
|
meereck
Joined: 09 Nov 2006 Posts: 173
|
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Sun Jan 31, 2010 4:59 am |
|
|
Yes, I didn't remember, that I was already involved in tracing the bug. Perhaps CCS users should
maintain a directory of known bugs, as CCS apparently isn't motivated to do? |
|
|
|