Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
06/17/02 12:07
Read: times


 
#24545 - RE: sprintf Formatter ????? in KEIL
"result on serial port (PC hyperterminal)
"test = -221846,0" STRING visible.


I presume that 1st number should be -21846?

I also presume that you must have disabled the ANSI integer promotions?

Now, let's consider your format string:
"test = %d,%dn"
The two %d specifiers tell sprintf to expect two int values; ie, two 16-bit values;
Without the ANSI integer promotions, your two values - 170 (=0xAA) and 0xAA - are both single bytes.

Therefore, when you run this, the 1st %d looks for its 16-bit value and takes both of your bytes at once to make 0xAAAA = -21846.
The behaviour of the 2nd %d - as you haven't supplied enough actual parameters - is undefined!

You need to be very careful that the actual parameters precisely match the format specifiers!

You must either change your specifiers, or cast your bytes to ints!


List of 4 messages in thread
TopicAuthorDate
sprintf Formatter ????? in KEIL            01/01/70 00:00      
RE: sprintf Formatter ????? in KEIL            01/01/70 00:00      
RE: sprintf Formatter ????? in KEIL            01/01/70 00:00      
RE: sprintf Formatter ????? in KEIL            01/01/70 00:00      

Back to Subject List