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

[Help] Printf strange behaviour: don't plot zero value

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



Joined: 04 May 2010
Posts: 7

View user's profile Send private message

[Help] Printf strange behaviour: don't plot zero value
PostPosted: Fri Aug 02, 2013 9:29 am     Reply with quote

Hi everyone

I got the following issue, i will really appreciate any help of you guys.

System info:
CCS 4.1
MPLAB 8.88
dSPIC 33FJ256GP506 @60Mhz

All the code it's fully functional, but i got an issue with printf.

Code:


//...Fuses, clock, use rs232, etc. (all set)


signed int32 temp;

void main(){

//..init dspic, port,etc. (all set)


  while(1){

     temp=100;
     printf("%Ld,",temp);
     temp=50;
     printf("%Ld,",temp);
     temp=0;
     printf("%Ld,",temp);
     temp=10;
     printf("%Ld\r,",temp);
 
     delay_ms(1000);

  }//end while

} //end main



Expected output:

Code:

100,50,0,10
100,50,0,10
100,50,0,10
100,50,0,10
...etc.


The output that i get

Code:

100,50,,10
100,50,,10
100,50,,10
100,50,,10
...etc.


So the problem is: I can't plot a zero value

temp must be signed int32, because it will be updated in a function, with the real value (this function is disabled for now)
I simplify the code to show my point that printf don't plot zero values

Any help will be appreciated


NOTE: All others variable types work fine, this issue is only with signed int32 variable type.

ie:
Code:

printf("%4.0f,",(float) temp);


Works fine, and is a workaround to this. but i want to understand why this fail using signed int32.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Aug 02, 2013 4:45 pm     Reply with quote

Quote:
temp=0;
printf("%Ld,",temp);

No one else has replied so I'll help somewhat. I don't have the PCD
compiler. So I tested your code with an 18F4620 with versions 4.141
and 5.010 in MPLAB simulator and it works OK. So it may be a bug with
PCD with your version.

Quote:
CCS 4.1

Also, this is not a version. Versions have four digits.
Ttelmah



Joined: 11 Mar 2010
Posts: 19369

View user's profile Send private message

PostPosted: Sat Aug 03, 2013 12:54 am     Reply with quote

I'd suspect the version might be quite early. PCD, had some printf problems in the past with 32bit integers, around the low 4.100's.
It gives the correct answer in 4.107, but is faulty in 4.099.
It will though work correctly, if you specify a field width. Just use:

printf("%1Ld,",temp);

Basically with a zero value, it displays nothing, rather than the zero. Specifying a single character minimum field width forces it to output one character in this situation, and the zero is then displayed.

Best Wishes
CoverUp



Joined: 04 May 2010
Posts: 7

View user's profile Send private message

PostPosted: Wed Aug 07, 2013 9:15 am     Reply with quote

Our version is CCS 4.104

i tried with

Code:

printf("%1Ld,",temp);


The output is

Code:

100,50, ,10
100,50, ,10
100,50, ,10
100,50, ,10
...etc.


So "nothing" is replaced by "space". So you guys are right, it's a PCD bug and we need to update.
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