gpt4 book ai didi

我可以将 NULL 传递给 modf/modff 吗?

转载 作者:行者123 更新时间:2023-12-05 08:48:41 24 4
gpt4 key购买 nike

modf() family of functions都带一个指针参数:

float       modff( float arg, float* iptr );
double modf( double arg, double* iptr );
long double modfl( long double arg, long double* iptr );

用于返回其输入arg的整数部分(小数部分为实际返回值)。

如果我只需要小数部分,我可以通过传递NULL来“跳过”整数部分的计算吗?

无论是我喜欢的 cppreference 页面,还是 man modff,都没有说明当您为 iptr 传递 NULL 时会发生什么,而一些其他标准库函数将 NULL 作为“忽略此参数”的指示。

最佳答案

standard没有定义这个

Description

2 The modf functions break the argument value into integral and fractional parts, each of which has the same type and sign as the argument. They store the integral part (in floating-point format) in the object pointed to by iptr.

Returns

3 The modf functions return the signed fractional part of value.

因此传递 NULL 时的行为将是未定义的。您可能会发现一些允许它的编译器,但任何依赖它的代码都不可移植(即使在同一编译器的不同版本之间)。

关于我可以将 NULL 传递给 modf/modff 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65578459/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com