Random problem (that is, problem with random())

Feng, Shuchen feng at bnl.gov
Sat Mar 26 01:23:37 UTC 2005


How about adding ?

#include <rtems/rtems_bsdnet_internal.h>

Kate

-----Original Message-----
From: Peter Dufault
To: RTEMS Users
Sent: 3/25/2005 5:20 PM
Subject: Random problem (that is, problem with random())

I have some on-the-hardware simulation software that uses random().  As 
far as I can tell random() is defined in stdlib.h and present in the 
libiberty library in RTEMS, but when I try to compile the functions 
using random in either C++ or C code I get warnings.

As an example, for this function:

#include <stdlib.h>

extern void foo(void);
extern void bar(long *l);

void foo(void) {
     int l = random();
     bar(&l);
}

I get this for gcc:
foo.c: In function ?foo?:
foo.c:7: warning: implicit declaration of function ?random?

and this for g++:
foo.cc: In function ?void foo()?:
foo.cc:7: error: ?random? was not declared in this scope

If I check stdlib.h in my /opt/rtems4.7 tree I find random in there:

int _EXFUN(random,(_VOID));

and when I put the declaration explicitly in my code (that is, I put 
"extern int random(void);" in my code) it compiles and links fine.

I hope to avoid tracking back where _EXFUN comes from and what might be 
up with my installation, but I do want to know if something is out of 
the ordinary, so:

Q1: Does this fail for anyone else?
Q2: Is it obvious to anyone what's up from the problem description?

RTEMS 4.7, powerpc MVME5500,
gcc-4.0-20050130 (that snapshot),
binutils-2.15 with the 20040519 patch
gdb-5.3
newlib 1.12.0
automake 1.9.2
autoconf 2.59

Peter

Peter Dufault
HD Associates, Inc.



More information about the users mailing list