Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/141.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何在c++;_C++_Parameters_Arguments_Placeholder_Gmp - Fatal编程技术网

C++ 如何在c++;

C++ 如何在c++;,c++,parameters,arguments,placeholder,gmp,C++,Parameters,Arguments,Placeholder,Gmp,我正在使用GMP任意精度算术库中的此函数: Function: void mpz_gcdext (mpz_t g, mpz_t s, mpz_t t, const mpz_t a, const mpz_t b) Set g to the greatest common divisor of a and b, and in addition set s and t to coefficients satisfying a*s + b*t = g. The value in g is always

我正在使用GMP任意精度算术库中的此函数:

Function: void mpz_gcdext (mpz_t g, mpz_t s, mpz_t t, const mpz_t a, const mpz_t b)

Set g to the greatest common divisor of a and b, and in addition set s and t to coefficients satisfying a*s + b*t = g. The value in g is always positive, even if one or both of a and b are negative (or zero if both inputs are zero). The values in s and t are chosen such that normally, abs(s) < abs(b) / (2 g) and abs(t) < abs(a) / (2 g), and these relations define s and t uniquely. There are a few exceptional cases:

If abs(a) = abs(b), then s = 0, t = sgn(b).

Otherwise, s = sgn(a) if b = 0 or abs(b) = 2 g, and t = sgn(b) if a = 0 or abs(a) = 2 g.

In all cases, s = 0 if and only if g = abs(b), i.e., if b divides a or a = b = 0.

If t is NULL then that value is not computed. 
函数:void mpz_gcdext(mpz_g,mpz_ts,mpz_t,const mpz_t a,const mpz_t b)
将g设置为a和b的最大公约数,另外将s和t设置为满足a*s+b*t=g的系数。g中的值始终为正值,即使a和b中的一个或两个为负值(或如果两个输入均为零,则为零)。选择s和t中的值时,通常情况下,abs(s)如果t为空,则不计算该值。

我不需要'g'或't'的值,也不希望仅为了传递给此函数而创建变量。我能做些什么来将某个占位符传递给这个特定的函数,我怎么能在C++中这样做呢?

你可能会超载函数。
void mpz_gcdext (mpz_t s, const mpz_t a, const mpz_t b)
{
    mpz_t g, t;
    // initialize g and t as needed
    mpz_gcdext(g, s, t, a, b);
}

这有用吗?

这样不行。如果库函数需要参数,则必须指定该参数。库函数的给定参数可能是可选的,如果是,库函数的文档将解释在这种情况下为该参数传递什么值。查看库函数的文档以了解更多信息。当然,我理解这对于输入参数是正确的,但我认为我可以对我不需要的输出参数使用任意的东西。不幸。非常感谢。“如果t为NULL,则不会计算该值”,所以至少对于该值,您的答案是微不足道的。如果您想跳过更新g,您可以查看
mpz\u gcdext
的代码,并根据需要调整它,自己调用底层的
mpn\u gcdext
。虽然没有文档记录,但显然也可以将s=NULL传递给函数。您可以向GMP发送一个补丁,该补丁也允许g=NULL…GMP的下一个版本将允许您调用
mpz\u gcdext(NULL,s,NULL,a,b)