Parameters 函数参数导致GMP中的分段错误

Parameters 函数参数导致GMP中的分段错误,parameters,segmentation-fault,gmp,Parameters,Segmentation Fault,Gmp,我试图更改函数extended_gcd中类型为mpz_t的d的值,然后将其传递回我的主函数,当我执行程序时,我得到了一个分段错误 int extended_gcd(mpz_t c, mpz_t a, mpz_t b) { mpz_t x, lastx, y, lasty, temp, quotient, temp2; mpz_init(temp); mpz_init(temp2); mpz_init(a); mp

我试图更改函数extended_gcd中类型为mpz_t的d的值,然后将其传递回我的主函数,当我执行程序时,我得到了一个分段错误

    int extended_gcd(mpz_t c, mpz_t a, mpz_t b)
    {

      mpz_t x, lastx, y, lasty, temp, quotient, temp2;

      mpz_init(temp); 
      mpz_init(temp2); 
      mpz_init(a);
      mpz_init(b);
      mpz_init(c);
      mpz_init(quotient); 
      mpz_init_set_ui(x,0); 
      mpz_init_set_ui(lastx,1);
      mpz_init_set_ui(lasty,0);
      mpz_init_set_ui(y,1);

while(!(mpz_cmp(b, 0)==0))
{
    mpz_set(temp, b);
    mpz_cdiv_q(quotient, a, b);
    mpz_mod(b, a, b);
mpz_set(a, temp);
    mpz_set(temp, x);
mpz_mul(temp2, quotient, x);
mpz_sub(x, lastx, temp2);
    mpz_set(lastx, temp);
    mpz_set(temp, y);
    mpz_mul(temp2, quotient, y);
mpz_sub(y, lasty, temp2);
    mpz_set(lasty, temp);                 
}

mpz_set(c, lastx);        
mpz_clear(x);
mpz_clear(y);
mpz_clear(lastx);
mpz_clear(lasty);
mpz_clear(temp);
mpz_clear(temp2);
mpz_clear(quotient);
 return 0;  
}

这是我的主要代码:

    extended_gcd(d,e,phi);  
    printf("d=");
    mpz_out_str(stdout, 10, d);
    printf("\n");
你知道哪里出了问题吗?我该怎么解决?
谢谢您的时间。

我发现了一个问题:您不应该对extended_gcd()的参数调用mpz_init()。您应该只对extended_gcd()中声明的mpz_t变量调用mpz_init()/mpz_clear()