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

PIC 24F Char Comparison

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



Joined: 19 Nov 2012
Posts: 23

View user's profile Send private message

PIC 24F Char Comparison
PostPosted: Mon Nov 19, 2012 9:04 am     Reply with quote

Hi Everyone,

Not sure this is related to my work environment, but I seem to encounter some pretty annoying bugs with compiler version 4.117 using MPLAB as the editor and simulator.

1. Why does this code think str[2] is NOT equal to ch, however str[2] is equal to 'i'? Had a similar issue with pointers but worked around with an exor comparison.

Code:

#include <24fj128GA010.h>
//#device PASS_STRINGS=IN_RAM

#fuses NODEBUG      // Debug Mode. 1.11   NODEBUG   No Debug mode for ICD
#fuses HS,PR_PLL    // Crystal HS, 4xPLL
#fuses NOIESO       // No 2-speed Start Up
#fuses NOJTAG       // No JTAG
#fuses NOPROTECT    // No Memory Protection
#fuses NOWDT        // No WatchDog Timer
#fuses NOCOE         // Debug Mode. 1.11   NODEBUG   No Debug mode for ICD

#use delay(clock=32M, crystal=8M)

#use rs232(UART1, STREAM=serial_debug, baud=9600, bits=8)

#include "string.h"

int main ()
{
  char str[] ="This is a simple string";
  char ch = 'i';
  int out = 0;
 

  if(str[2] == ch){
     out = 1;}
 
  if(str[2] == 'i'){
     out = 2;}
     
 
  return 0;
}


2. Often, not always when i press 'step over' the code executes until the end of the program. I read somewhere that others had this issue but could prevent that behavior with breakpoints. This doesn't seem to work for me.

Help much appreciated.
Regards,
John
Ttelmah



Joined: 11 Mar 2010
Posts: 19499

View user's profile Send private message

PostPosted: Mon Nov 19, 2012 10:22 am     Reply with quote

Just built this, loaded it into MPLAB (8.85), and step over happily steps to out=1, and out=2. Tried a dozen times.
There are some problems with the code. Main, can not return anything. Where is it meant to return the value 'to'?... There is no OS. Then the code effectively drops of the end, and executes a PWRSAV #0 instruction.
This is why you should always have a stopper routines at the end to prevent this from happening.
It is perhaps interesting to note that the compiler uses a different compare for the two situations, using xor for the later, and cp for the former. However the code generated is perfectly sensible. I'd suggest that possibly your version of MPLAB has a problem.

Best Wishes
john.ma



Joined: 19 Nov 2012
Posts: 23

View user's profile Send private message

PostPosted: Mon Nov 19, 2012 11:12 am     Reply with quote

Thanks for your quick reply.
I've revised my configuration and cant seem to see anything wrong. I will try a newer compiler version...

I found this http://www.ccsinfo.com/forum/viewtopic.php?t=44538 and saw in the version release notes:

4.117 A bug in complex expressions involving != or == for PCD is fixed
4.117 The #TYPE SIGNED directive now also affects char declarations
4.117 An undeserved error from SPI_XFER in PCM/PCH is fixed

I wonder if the fix solved one issue and started another... :/
Ttelmah



Joined: 11 Mar 2010
Posts: 19499

View user's profile Send private message

PostPosted: Mon Nov 19, 2012 1:09 pm     Reply with quote

I built with 4.118, which was the closest I had to .117.

Best Wishes
john.ma



Joined: 19 Nov 2012
Posts: 23

View user's profile Send private message

PostPosted: Mon Nov 19, 2012 1:25 pm     Reply with quote

Thanks for taking the time Ttelmah, much appreciated
john.ma



Joined: 19 Nov 2012
Posts: 23

View user's profile Send private message

Confirmed. Equality errors with 4.117!
PostPosted: Tue Nov 20, 2012 3:54 pm     Reply with quote

So tested it on a PHD students version of CCS (4.138) and its fine. Its a bug across all ~200ish computers in my deparment...
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