avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] Initilizing complex const arrays : syntax ?


From: David Kelly
Subject: Re: [avr-gcc-list] Initilizing complex const arrays : syntax ?
Date: Mon, 19 Sep 2005 20:28:21 -0500

On Mon, Sep 19, 2005 at 10:19:41AM -0400, Dave Hansen wrote:

Try something like

  #include <stdlib.h>
  ...
  div_t qr;

    while(x) {
        qr = div(x,10);
        buffer[i--] = qr.rem + '0';
        x = qr.quot;
    }

I'm not certain this is optimal.  I haven't looked closely, but it
looks like it should be.  It certainly has the opportunity to be.

Yeah! Thats what I was looking for. Exactly a FORTH /mod (pronounced
"slash mod")!

div() costs nothing to implement because its almost certain the avr-libc
division primatives will be included at link time. div() is only a macro
wrapping that routine so we can get at both dividend and remainder using
a struct. The exact same primative is used for division and modulo, the
only difference is which result is picked up.

Might be nice to add a udiv() and uldiv() to existing div() and ldiv().

--
David Kelly N4HHE, address@hidden
========================================================================
Whom computers would destroy, they must first drive mad.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]