Re: [cc65] discarded if statement

From: Ullrich von Bassewitz <>
Date: 2004-08-09 13:11:46
On Mon, Aug 09, 2004 at 12:58:51PM +0200, Groepaz wrote:
> looks like a succesful attempt of earning some more grey hair to me :o)

Code like this can be useful. Assume a routine that converts a number into a
string. The usual problem with such a routine is that conversion starts at the
least significant digit, while we need to write the most significant digit as
the first digit to the buffer. There are several solutions for this problem.
A possible one uses the stack:

        void convert (unsigned val, char* buf)
            char c;

            push ('\0');
            do {
                push ((val % 10) + '0');
                val = val / 10;
            } while (val != 0);

If the data is then poped from stack, it has the "right" order for the
converted number:

            do {
                c = *buf++ = pop ();
            } while (c  != '\0');



Ullrich von Bassewitz                        
To unsubscribe from the list send mail to with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Mon Aug 9 13:11:50 2004

This archive was generated by hypermail 2.1.8 : 2004-08-09 13:11:58 CEST