Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

warning: implicit declaration of function '__gmpz_out_str' is invalid in C99

I just installed the gmp Multiple Precision Arithmetic Library on my mac. Whenever I compile a program, I get this warning:

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

I will get an executable that works, but I always get this when I use this particular function. Here is what the main file looks like:

#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;
}

Anyone know what the issue is?

like image 362
Andrew Avatar asked Nov 05 '25 14:11

Andrew


1 Answers

From the GMP documentation:

5.12 Input and Output Functions

Functions that perform input from a stdio stream, and functions that output to a stdio stream, of mpz numbers. Passing a NULL pointer for a stream argument to any of these functions will make them read from stdin and write to stdout, respectively.

When using any of these functions, it is a good idea to include stdio.h before gmp.h, since that will allow gmp.h to define prototypes for these functions.

If you change the top of your file from

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

to

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

then the error message should go away.

like image 78
r3mainer Avatar answered Nov 08 '25 13:11

r3mainer