gpt4 book ai didi

c - C 中的特殊测试位函数

转载 作者:行者123 更新时间:2023-11-30 17:31:30 25 4
gpt4 key购买 nike

/* Returns 1 if the corresponding bit in the given seq_bits indicates true
* and curr_seqno is within range of last_seqno. Otherwise returns 0.
*/
static inline int samle_test_bit(const unsigned long *seq_bits,
uint32_t last_seqno, uint32_t curr_seqno)
{
int32_t diff;

diff = last_seqno - curr_seqno;
if (diff < 0 || diff >= TQ_LOCAL_WINDOW_SIZE)
return 0;
else
return test_bit(diff, seq_bits) != 0;
}

curr_seqno=当前序列号
last_seqno=最后一个序列号

我不明白这个功能。似乎总是测试位 1,因为 diff=last_seqno-curr_seqno 主要是 1。test_bit(1, seq_bits)

如果你想测试 seq_bits 中的其他位怎么办?

最佳答案

该函数正在检查last_seqno和curr_seqno之间的差异是否小于TQ_LOCAL_WINDOW_SIZE,并且curr_seqno不大于last_seqno。

它看起来像验证,但您更改了一些内容,因为第二次调用与明显的尾递归调用的原型(prototype)不匹配。在 K&R C 中,您有时可能会错误地使用局部变量作为参数,但您提供的这个示例的类型是错误的..所以正如发布的那样,这是无意义的! *

  • 看到的解释是,这是一个包装器,并不意味着递归调用。

关于c - C 中的特殊测试位函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24592696/

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