| ??? 08/22/05 12:51 Read: times |
#99813 - sprintf() is fairly large Responding to: ???'s previous message |
Kunaal Lagwankar said:
Also, wouldnt use of sprintf be wiser rather than implementing all the logic ? Unless I had a bunch more formatting to do elsewhere, I would try to avoid sprintf(), which is quite costly code-wise. Admittedly, the tostr()/rpt() pair are a bit inefficient and could be combined into something smaller -- a variation of: /****************************************************************************
*
* NAME: UsToStr
* PURPOSE: Convert unsigned short to decimal string.
*
* SYNOPSIS: void UsToStr(char *s, unsigned short bin, unsigned char n);
*
* DESCRIPTION:
*
* The function stores a NUL-terminated string, in "n" + 1 (plus 1 for
* the NUL string terminator) successive elements of the array whose
* first element has the address "s", by converting "bin" to "n" decimal
* characters.
*
****************************************************************************/
void UsToStr(char *s, unsigned short bin, unsigned char n)
{
s += n;
*s = ' ';
while (n--)
{
*--s = (bin % 10) + '0';
bin /= 10;
}
} |
| Topic | Author | Date |
| Keil C51-optimization & Pointers | 01/01/70 00:00 | |
| Bad array index | 01/01/70 00:00 | |
| oops!! | 01/01/70 00:00 | |
| buff[] is auto, not static | 01/01/70 00:00 | |
| Back to basics | 01/01/70 00:00 | |
| Don't shoot the pianist! | 01/01/70 00:00 | |
| Hex file size | 01/01/70 00:00 | |
| Optimization pointers | 01/01/70 00:00 | |
| sprintf() is fairly large | 01/01/70 00:00 | |
| So start a new thread, then! | 01/01/70 00:00 | |
| pls...help | 01/01/70 00:00 | |
I disagree | 01/01/70 00:00 | |
| My dear Watson ! | 01/01/70 00:00 | |
| One size fits all | 01/01/70 00:00 | |
| bin = hex / 2.8 | 01/01/70 00:00 | |
| hexmap | 01/01/70 00:00 | |
| A bit of a sweeping generalisation!! | 01/01/70 00:00 | |
| Keil C51-optimization & Pointers | 01/01/70 00:00 |



