This is the mail archive of the
cygwin
mailing list for the Cygwin project.
Re: Using rand_r
On 2009-05-14 05:49Z, Nicholas Sherlock wrote:
> David Billinghurst wrote:
> > Nicholas Sherlock wrote:
> >> Hey everyone,
> >>
> >> I'm trying to use the function rand_r with gcc-4 in Cygwin 1.7, all
> my packages are up to date. It's supposed to be defined in stdlib.h, and
> I can see it there. But if I compile a program which uses it, I get:
> >>
> >> warning: implicit declaration of function 'rand_r'.
> >>
> >> The reason seems to be the check for #ifndef __STRICT_ANSI__ in
> stdlib.h. Even though I'm compiling with -std=c99, __STRICT_ANSI__ still
> gets declared, so the definition of rand_r is unavailable. This seems to
> be the same problem stated here:
'-std=c99' correctly gives a diagnostic because rand_r() is not in C99.
> > Try -std=gnu99. It doesn't define __STRICT_ANSI__
> >
> > This doesn't answer your question, unfortunately.
>
> Thanks, that does solve my immediate problem. But I'm really hoping to
> compile as vanilla C99 as I can manage, since I'll also be using my code
> with non-GNU compilers.
If you want consistently identical results with different compilers,
then you'll need to write your own routine anyway (which you can do
in strictly-conforming C). See the rationale for myrand() here:
http://www.opengroup.org/onlinepubs/000095399/functions/rand.html
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/