avr-libc-dev
[Top][All Lists]
Advanced

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

Re: [avr-libc-dev] rand(3) in avr-libc


From: Theodore A. Roth
Subject: Re: [avr-libc-dev] rand(3) in avr-libc
Date: Mon, 9 Sep 2002 09:05:45 -0700 (PDT)

On Mon, 9 Sep 2002, Joerg Wunsch wrote:

:) Hi all,
:)
:) after looking at FreeBSD's rand.c implementation, i noticed that
:) avr-libc already has one, apparently taken from FreeBSD's revision
:) 1.2.  This file has an implementation for thread support (rand_r())
:) which we IMHO don't need, while it doesn't use the improved algorithm
:) that is used in random(3), as implemented in FreeBSD's rev 1.3 (which
:) is much preferrable, as i understand it).
:)
:) Also, RAND_MAX was set to 0x7fffffff, but the return type is only int
:) (which is unfortunately mandated by the ISO C standard).  This doesn't
:) fit very well...

Your patch is still using longs inside the function and then returning an
int. Aren't longs 32 bit and ints 16 bit for avr? What's the effect of
this? Should we return long in this case?

:)
:) Finally, only RAND_MAX was really in <stdlib.h> by now, while rand()
:) and srand() aren't documented.
:)
:) I'll append a diff for the improved version minus support for
:) rand_r(), plus the documentation.
:)
:) Opinions anyone?  Should i keep rand_r() support?

rand_r() might still be needed for avr. Even without threads, you may
still need to use re-entrant functions in certain cases (for example,
interrupts, but that's a poor example ;-)

Ted Roth





reply via email to

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