problem with example of mpn_gcd
William Stein
wstein at gmail.com
Sat Jul 29 20:29:19 CEST 2006
> On Jul 29, 2006, at 1:50 AM, Jiang wf wrote:
>> hello, everyone,
>>
>> I just want use mpn_gcd to make a program, that can calculate gcd
>> of two big integers, the following is my code named agcd.c:
>>
>>
>>
>> #include <stdio.h>
>> #include <gmp.h>
>>
>> main (int argc, char **argv)
>> {
>> mpz_t a, b, p;
>>
>> if (argc != 3)
>> { printf ("Usage: %s <number> <number>\n", argv[0]); exit
>> (1); }
>>
>> /* Initialize and assign a and b from base 10 strings in argv */
>> mpz_init_set_str (a, argv[1], 10);
>> mpz_init_set_str (b, argv[2], 10);
>> /* Initialize p */
>> mpz_init (p);
>>
>>
>> /* compute the gcd of a and b*/
>> mp_size_t mpn_gcd (mp_limb_t *p, mp_limb_t *a,
>> mp_size_an, mp_limb_t *b, mp_size_t bn)
>>
>> /* Print p in base 10 */
>> mpz_out_str (stdout, 10, p);
>> fputc ('\n', stdout);
>>
>> /* Since we're about to exit, no need to clear out variables */
>> exit (0);
>> }
>>
>>
>>
>> and when compiled, got the following error:
>>
>> agcd.c: In function 'main':
>> agcd.c:9: warning: incompatible implicit declaration of built-in
>> function 'exit'
>> agcd.c:20: error: syntax error before 'mp_size_an'
>>
>>
>>
>>
>> so, please, anyone can give me some advise about this problem, thanks!
You pasted in the declaration of some random function that had "gcd"
in it instead of calling the correct gmp function. See below:
#include <stdio.h>
#include <gmp.h>
main (int argc, char **argv)
{
mpz_t a, b, p;
if (argc != 3)
{ printf ("Usage: %s <number> <number>\n", argv[0]); return 1; }
/* Initialize and assign a and b from base 10 strings in argv */
mpz_init_set_str (a, argv[1], 10);
mpz_init_set_str (b, argv[2], 10);
/* Initialize p */
mpz_init (p);
/* compute the gcd of a and b*/
mpz_gcd(p, a, b);
/* Print p in base 10 */
mpz_out_str (stdout, 10, p);
fputc ('\n', stdout);
/* Since we're about to exit, no need to clear out variables */
return(0);
}
--
William Stein
Associate Professor of Mathematics
University of Washington
More information about the gmp-discuss
mailing list