代码之家  ›  专栏  ›  技术社区  ›  Amarth Gûl

函数rand\r的隐式声明

  •  1
  • Amarth Gûl  · 技术社区  · 5 年前

    我知道有很多类似的问题,但到目前为止,我还没有找到一个可以解决我的情况。

    制作文件时,我被提示

    warning: implicit declaration of function ‘rand_r’ [-Wimplicit-function-declaration]
    

    但我已经包括了 stdlib.h unistd.h

    我在Linux上运行这个程序,我的makefile大致如下:

    prog: prog.o
        gcc -g -o $@ $^ -lpthread
    
    %.o:%.c *.h
        gcc -ansi -pedantic -Wimplicit-function-declaration -Wreturn-type -g -c $< -o $@
    

    谢谢你

    1 回复  |  直到 5 年前
        1
  •  1
  •   xhienne    5 年前

    rand_r() manpage 内容如下:

    函数rand()和srand()符合SVr4、4.3BSD、C89、C99、POSIX.1-2001。函数rand_r()来自POSIX.1-2001。POSIX.1-2008将rand\u r()标记为已过时。

    -ansi (C89/C90)从而限制您 rand() srand() .