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 support@ccsinfo.com

+= operator bug on byte returning of sprintf() ?

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



Joined: 29 Sep 2006
Posts: 114

View user's profile Send private message

+= operator bug on byte returning of sprintf() ?
PostPosted: Wed Oct 07, 2009 9:28 am     Reply with quote

Hi,

Up and including version 4093 I could use the += operator on the byte number that is returned when calling sprintf() function. Above 4093 this goes totally wrong. Tested 4095/99
Question is -why- and are there other functions with this strange behaviour.... I really hope not

PS. below is a snippet. I use this construction to conditionally build a string. And also to incorporate some of my own much faster int32 formatting functions.

Code:

#include <18F4620.h>

#fuses INTRC_IO, NOFCMEN, IESO, PUT
#fuses NOBROWNOUT, NOWDT, NOPBADEN, LPT1OSC 
#fuses MCLR, STVREN, NOLVP                         

#use delay(clock=4000000)
#use RS232(stream=debug, Baud=9600, Bits=8, Xmit=PIN_B6, Rcv=PIN_B7, DISABLE_INTS)


void main() {
  int8 iEoB;
  char WrBuf[80];
 
  setup_oscillator(OSC_INTRC | OSC_4MHZ);
  fprintf(debug, "<Anykey>: Start test program\n");
  fgetc(debug);

  // not working anymore
  iEoB=0;
  fprintf(debug, "iEob=%u\n",iEob);
  iEob += sprintf(WrBuf+iEoB,"Hi, why is ");
  fprintf(debug, "iEob=%u\n",iEob);
  iEob += sprintf(WrBuf+iEoB,"this not worning anymore?\n");
  fprintf(debug, "iEob=%u\n",iEob);
  fprintf(debug, "%s",WrBuf);
 
 
  // this does work
  iEoB=0;
  fprintf(debug, "iEob=%u\n",iEob);
  iEob = iEob + sprintf(WrBuf+iEoB,"Hi, why isn't ");
  fprintf(debug, "iEob=%u\n",iEob);
  iEob = iEob + sprintf(WrBuf+iEoB," += working anymore?\n");
  fprintf(debug, "iEob=%u\n",iEob);
  fprintf(debug, "%s",WrBuf);

  while(1);
}


Quote:

Output:
iEob=0
iEob=0
iEob=0
this not worning anymore?
iEob=0
iEob=14
iEob=35
Hi, why isn't += working anymore?


Any thoughts welcome...
Kind regards,
Edwin.
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Wed Oct 07, 2009 9:40 am     Reply with quote

The help in my version of CCS PCH C Compiler, Version 4.011, 26184 07-Oct-09 16:13

Shows that sprintf does not return anything!
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Wed Oct 07, 2009 10:03 am     Reply with quote

Quote:
Version 4.011, 26184 07-Oct-09
Somewhat outdated. The most recent help clarifies
Quote:
Returns: Bytes is the number of bytes written to string.
(According to the C standard)

Quote:
Question is -why-
Because -the compiler was changed, apparently without sufficient testing. You can see, that several instructions are "optimized away" in the newer code.
Quote:
are there other functions with this strange behaviour
You never know.
Torello



Joined: 29 Sep 2006
Posts: 114

View user's profile Send private message

PostPosted: Fri Oct 16, 2009 2:51 pm     Reply with quote

CCS has aswered on my bug report that it is indeed a bug. Will be repaired in the next update.

Regards,
Edwin.
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