(; uint64_count &&&!*value; uint64_count--) 是什么意思



我想了解这个函数在实践中的作用:

inline std::size_t get_significant_uint64_count_uint(
const std::uint64_t *value, std::size_t uint64_count)
{
value += uint64_count - 1;
for (; uint64_count && !*value; uint64_count--)
{
value--;
}
return uint64_count;
}

它看起来既改变了value,也改变了uint64_count。我找不到&&做什么,但我猜这里是"one_answers"。无论如何,看起来for循环运行到uint64_count>0*value!=0。但我不明白其中的逻辑。

Function from here

看起来它既修改了value也修改了uint64_count

是的。

我找不到&&做什么

真的吗?任何像样的c++参考书/书籍都应该涵盖逻辑运算符,在这里是逻辑与。

我猜这里是用于& & & &;

是的。

看起来for循环运行到uint64_count>0*value!=0

。直到uint64_count为0或*value不为0为止。

难看的代码

inline std::size_t get_significant_uint64_count_uint(
const std::uint64_t *value, std::size_t uint64_count)
{
value += uint64_count - 1;
for (; uint64_count && !*value; uint64_count--)
{
value--;
}
return uint64_count;
}

记住你是按值传递两个参数的。因此,修改value或count在这个方法之外不会做任何事情。它们是原件的副本。

所以,value是一个指向内存的指针。代码将其按计数加1,然后代码开始从该位置返回到开始查找空字节。

所以我猜它试图找到数据中最后null的字节数

为什么?没有线索。

函数从value所指向的数组末尾开始运行,直到在数组中找到值为0或到达数组末尾为止,并返回值为0的数组索引。

最新更新