CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Comparing int1 with float. Different results. Compiler bug?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
erik.wallebom



Joined: 30 Jan 2010
Posts: 2
Location: Sweden

View user's profile Send private message Visit poster's website

Comparing int1 with float. Different results. Compiler bug?
PostPosted: Sat Jan 30, 2010 12:17 pm     Reply with quote

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

View user's profile Send private message

Compiler bug!
PostPosted: Sat Jan 30, 2010 4:03 pm     Reply with quote

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

View user's profile Send private message Visit poster's website

PostPosted: Sat Jan 30, 2010 7:04 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Jan 31, 2010 4:03 am     Reply with quote

arrays of int1 are still little buggy:
see my post regarding comparison of two int1 arrays:
http://ccsinfo.com/forum/viewtopic.php?t=40661

Cheers
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Sun Jan 31, 2010 4:59 am     Reply with quote

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?
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group