why defined implicit

B

Bart Rider

I've written a short c-programm using srand48 and drand48.
After compiling with gcc -
gcc -o foo foo.c -W -Wall -pedantic -ansi
- I get the warnings -
foo.c: In function `main':
foo.c:7: warning: implicit declaration of function `srand48'
foo.c:8: warning: implicit declaration of function `drand48'
-. (The short example is at the end.)

No I wonder why. I checked the man pages and googled for it.
The correct header file, stdlib.h, is included. Even compiling
with switch -lc to explicitely include libary libc does not
make the warnings vanish.

Do I have to include another header file? Or is it system
specific and, thus, maybe OT here.

Thanks in advance,
Bart

/* start file foo.c */

#include <stdlib.h>
#include <time.h>

int main( void ) {

srand48( time(0) );
drand48();
return 0;

} /* of main */

/* end of file foo.c */
 
M

manoj1978

Bart said:
I've written a short c-programm using srand48 and drand48.
After compiling with gcc -
gcc -o foo foo.c -W -Wall -pedantic -ansi
- I get the warnings -
foo.c: In function `main':
foo.c:7: warning: implicit declaration of function `srand48'
foo.c:8: warning: implicit declaration of function `drand48'

These functions are not part of ANSI C.
 
P

Philip Potter

Bart Rider said:
I've written a short c-programm using srand48 and drand48.
After compiling with gcc -
gcc -o foo foo.c -W -Wall -pedantic -ansi
- I get the warnings -
foo.c: In function `main':
foo.c:7: warning: implicit declaration of function `srand48'
foo.c:8: warning: implicit declaration of function `drand48'
-. (The short example is at the end.)

No I wonder why. I checked the man pages and googled for it.
The correct header file, stdlib.h, is included. Even compiling
with switch -lc to explicitely include libary libc does not
make the warnings vanish.

Do I have to include another header file? Or is it system
specific and, thus, maybe OT here.

It is system specific, and thus OT here.

<OT>
Your manpage probably has a "CONFORMING TO" section, which will tell you if
a given function is part of ANSI C or not. For example on my machine "man
fopen" says that fopen() conforms to "ANSI X3.159-1989 ( ANSI C )", while
"man strdup" says that strdup() conforms to "SVID 3, BSD 4.3" with a notable
absence of ANSI C. Even though strdup() is included in the standard header
<string.h> on my system, it is not a standard function.

Note that manpages are not the law, however. If the manpage says one thing
and the Standard another, the Standard wins.
</OT>

Philip
 
B

Bart Rider

Philip said:
It is system specific, and thus OT here.

<OT>
Your manpage probably has a "CONFORMING TO" section, which will tell you if
a given function is part of ANSI C or not. For example on my machine "man
fopen" says that fopen() conforms to "ANSI X3.159-1989 ( ANSI C )", while
"man strdup" says that strdup() conforms to "SVID 3, BSD 4.3" with a notable
absence of ANSI C. Even though strdup() is included in the standard header
<string.h> on my system, it is not a standard function.

Note that manpages are not the law, however. If the manpage says one thing
and the Standard another, the Standard wins.
</OT>

Philip

Ah, ok, thanks for your answers.
In future I will read the man pages more ... uhm ... beady-eyed,
especially the ones I found with google since on my system,
solaris (SunOS ... 5.10 Generic_118855-14 i86pc i38), the man
pages don't contain a conforming section.

Best regards,
Bart
 
J

jmcgill

Bart said:
I've written a short c-programm using srand48 and drand48.
After compiling with gcc -
gcc -o foo foo.c -W -Wall -pedantic -ansi
- I get the warnings -
foo.c: In function `main':
foo.c:7: warning: implicit declaration of function `srand48'
foo.c:8: warning: implicit declaration of function `drand48'
-. (The short example is at the end.)

No I wonder why. I checked the man pages and googled for it.
The correct header file, stdlib.h, is included.

The manpage on my platform for drand48(3) which includes drand48,
erand48, lrand48, nrand48, mrand48, jrand48, srand48, seed48, lcong48
admonishes:

These functions are declared obsolete by SVID 3, which states that
rand(3) should be used instead.

Which leads to an interesting dilemma, for when you look at the rand(3)
man page, you will be told:

The function rand() is not reentrant or thread-safe .... this function
will be a weak pseudo-random generator. Try drand48_r(3) instead.
[which is a GNU extension on my platform...]

Of course you are asking your compiler to warn you about this, with
-ansi -pedantic, since these functions are SysV-ish, not ANSI-C-ish, or
even POSIX, anyway. Looking at stdlib.h on my platform, I'm not sure
how you'd have your cake and eat it too, because I imagine there is no
switch that gives you both pedantic warnings about ANSI compliance and
also declares __SVID
 
K

Knemon

Bart said:
I've written a short c-programm using srand48 and drand48.
After compiling with gcc -
gcc -o foo foo.c -W -Wall -pedantic -ansi
- I get the warnings -
foo.c: In function `main':
foo.c:7: warning: implicit declaration of function `srand48'
foo.c:8: warning: implicit declaration of function `drand48'
-. (The short example is at the end.)

No I wonder why. I checked the man pages and googled for it.
The correct header file, stdlib.h, is included. Even compiling
with switch -lc to explicitely include libary libc does not
make the warnings vanish.

srand48 and drand48 are not -std=c89 (your -ansi switch) or -std=c99
functions. They are therefore not defined in <stdlib.h> when you invoke
gcc with -ansi. If you want these non-standard functions to have their
declarations visible in <stdlib.h> (a violation of the standard), you
must leave off any of -ansi, -std=c89, -std=c99 or equivalents.
<ot>
gcc in default mode is not a standard C compiler, so the simple
gcc foo.c -o foo
would probably work for you (or -std=gnu89 or -std=gnu99).
Do I have to include another header file? Or is it system
specific and, thus, maybe OT here.

srand48 and drand48 are, indeed, system specific, non-standard, and OT here.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,225
Members
46,815
Latest member
treekmostly22

Latest Threads

Top