警告:在C99中,对函数'__gmpz_out_str'的隐式声明无效。

3

我刚在我的Mac上安装了gmp多精度算术库。每当我编译一个程序时,都会出现以下警告:

warning: implicit declaration of function '__gmpz_out_str' is
  invalid in C99 [-Wimplicit-function-declaration]
     mpz_out_str(stdout,10,p);
/usr/local/include/gmp.h:951:21: note: expanded from macro 'mpz_out_str'
#define mpz_out_str __gmpz_out_str

我会得到一个可执行文件,但每次使用特定函数时都会出现这种情况。以下是主文件的样子:
#include <gmp.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

void fact(int n){
  int i;
  mpz_t p;

  mpz_init_set_ui(p,1); /* p = 1 */
  for (i=1; i <= n ; ++i){
    mpz_mul_ui(p,p,i); /* p = p * i */
  }
  printf ("%d!  =  ", n);
  mpz_out_str(stdout,10,p);
  mpz_clear(p);

    }

    int main(int argc, char * argv[]){
  int n;


  if (argc <= 1){
    printf ("Usage: %s <number> \n", argv[0]);
    return 2;
  }

  n = atoi(argv[1]);
  assert( n >= 0);
  fact(n);


  return 1;
}

有人知道这个问题是什么吗?

1个回答

8
GMP文档中得知:

5.12 输入和输出函数

这些函数可以从stdio流中读取输入,或将mpz数输出到stdio流中。如果将流参数传递为NULL指针,则这些函数将分别从stdin读取并写入stdout

使用这些函数时,建议在gmp.h之前包含stdio.h,因为这样可以允许gmp.h为这些函数定义原型。

如果您将文件顶部从以下代码:

#include <gmp.h>
#include <stdio.h>

to

#include <stdio.h>
#include <gmp.h>

那么错误消息应该会消失。


如何检测一个库是否垃圾:它是否依赖于用户按特定顺序包含其他头文件? - Lundin

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接