我正在尝试创建一个返回类型 mpfr_t 的函数,但在其声明中出现错误。头文件声明如下(mpfr.h 是本地的):
#include "include/mpfr.h"
mpfr_t calcWinProb(int x);
但是当我尝试编译时出现以下错误:
error: âcalcWinProbâ declared as function returning an array
有什么想法吗?
最佳答案
C 语言不允许数组作为返回类型,mpfr_t
肯定是:
typedef __mpfr_struct mpfr_t[1];
引用 N1570(C11 草案)6.7.6.3/1
函数声明符(包括原型(prototype)):
A function declarator shall not specify a return type that is a function type or an array type.
这违反了约束,因此您的编译器有义务进行诊断(例如编译错误)。
您可以采取的措施是将 mpfr_t
替换为 mpfr_ptr
(指向结构的指针)类型或重新设计您的声明,因此 mpfr_t
是参数之一(可能是第一个),而不是返回类型,在这种情况下可能是 void
。后一个解决方案似乎与 MPFR API 更加一致.
关于c - mpfr_t函数声明错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27535989/