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?
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
mpznumbers. Passing aNULLpointer for a stream argument to any of these functions will make them read fromstdinand write tostdout, respectively.When using any of these functions, it is a good idea to include
stdio.hbeforegmp.h, since that will allowgmp.hto 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With