antirez / antirez/smaz

"warning: implicit declaration of function ‘random’" message when compiling

Aperta
#15 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
C
Stelle
1.2k
Fork
133
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

When I compile, I get the following warning:

```
$ make clean ; make
rm -rf smaz_test
gcc -o smaz_test -O2 -Wall -W -ansi -pedantic smaz.c smaz_test.c
smaz_test.c: In function ‘main’:
smaz_test.c:58:18: warning: implicit declaration of function ‘random’ [-Wimplicit-function-declaration]
ranlen = random() % 512;
```

The program compiles and the tests pass, so it looks like this warning is non-critical.

From looking around, I found an [SO question/answer that offers a solution](https://stackoverflow.com/questions/575350/why-cant-gcc-find-the-random-interface-when-std-c99-is-set/1085096#1085096).

Adding the `-D_XOPEN_SOURCE=600` option to `gcc` in the `Makefile` fixes the issue for me:

```
$ git diff
diff --git a/Makefile b/Makefile
index 62e8ccb..eecbac7 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
all: smaz_test

smaz_test: smaz_test.c smaz.c
- gcc -o smaz_test -O2 -Wall -W -ansi -pedantic smaz.c smaz_test.c
+ gcc -D_XOPEN_SOURCE=600 -o smaz_test -O2 -Wall -W -ansi -pedantic smaz.c smaz_test.c

clean:
rm -rf smaz_test
```

My system information:

```
$ gcc --version
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.12) 5.4.0 20160609
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

```

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.