![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
Torello
Joined: 29 Sep 2006 Posts: 118
|
+= operator bug on byte returning of sprintf() ? |
Posted: Wed Oct 07, 2009 9:28 am |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
Wayne_
Joined: 10 Oct 2007 Posts: 681
|
|
Posted: Wed Oct 07, 2009 9:40 am |
|
|
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! |
|
![](templates/subSilver/images/spacer.gif) |
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Wed Oct 07, 2009 10:03 am |
|
|
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)
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. |
|
![](templates/subSilver/images/spacer.gif) |
Torello
Joined: 29 Sep 2006 Posts: 118
|
|
Posted: Fri Oct 16, 2009 2:51 pm |
|
|
CCS has aswered on my bug report that it is indeed a bug. Will be repaired in the next update.
Regards,
Edwin. |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|