我正在尝试学习如何在c中使用GNU GMP库,我编写了该程序来查看mpz_t mpq_numref( mpq_t N)
和mpz_t mpq_denref( mpq_t N)
的工作方式。我收到一个错误,并且真的不知道如何修改代码才能使其正常工作。
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <gmp.h>
int main()
{
mpq_t u, v;
mpz_t a,b,c;
mpz_init(a);
mpz_init(b);
mpq_init( u );
mpq_init( v );
mpq_set_si( u, -6 ,2);
mpq_canonicalize( u );
a= mpq_numref( u );
b= mpq_denref( u );
gmp_printf( "u =%Zd/%Zd\n", a,b );
return 0;
}
我得到的错误是:
error: incompatible types when assigning to type ‘mpz_t’ from type ‘struct __mpz_struct *’
a= mpq_numref( u );
^
7.c:21:8: error: incompatible types when assigning to type ‘mpz_t’ from type ‘struct __mpz_struct *’
b= mpq_denref( u );
^
非常感谢您的帮助
最佳答案
仔细阅读错误消息将为您提供答案。 mpq_numref
和mpq_denref
函数都返回指向__mpz_struct
类型-> struct __mpz_struct *
的指针。
注意函数和数据类型的类型签名,在类型T
和其对应的指针类型T *
之间不可能进行隐式转换。
关于c - 问:从“struct __mpz_struct *”类型分配为“mpz_t”类型时是否存在不兼容的类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33791162/