Random problem (that is, problem with random())
Peter Dufault
dufault at hda.com
Fri Mar 25 22:20:35 UTC 2005
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