gpt4 book ai didi

c - 什么是 "Clang-Tidy: Function is within a recursive call chain"?如何解决?

转载 作者:行者123 更新时间:2023-12-04 02:31:30 70 4
gpt4 key购买 nike

我正在用 C 编写一个处理字符串的函数,它是递归的。基本上它所做的是在一些字符和 '\0' 之间找到一个字符串。 .如果之前找到 '\0' ,它击中特定字符,它将递归调用自身。
在 CLion 中编写它时,我看到了 Clang-Tidy 的警告,这是我以前从未见过的。它说

Clang-Tidy: Function 'function' is within a recursive call chain


我想知道它是 CLion 20.02 的新功能吗(我最近更新了它)?此外,我该如何解决?
这是我的代码。
char *function(char *pos, <some arguments>) {
char *temp = pos + 1;
while (1) {
if (*temp == '\0') {
return temp;
} else if (*temp == '<something>') {
*temp = '\0';
if (*(temp + 1) == '\0') {
return function(temp + 1, <some arguments>);
} else if (*(temp + 1) == '<something>') {
if (*(temp + 2) == '\0') {
return function(temp + 2, <some arguments>);
} else {
return function(temp + 1, <some arguments>);
}
} else {
return function(temp, <some arguments>);
}
}
temp++;
}
}

最佳答案

是的,recent Clang-Tidy diagnoses recursion .如果您有意编写一个递归函数,并且您确信它不能在不允许递归的上下文中使用(例如,请参阅 Clang-Tidy 文档中的引用资料),那么忽略该警告是合理的。由于“不允许”通常是一个策略问题而不是技术问题,因此您应该考虑清楚地记录该函数是递归的。并且您应该考虑不使用递归,这通常更适合实际代码。
这张支票不在 Clang-Tidy 10 .我找不到 Clang-Tidy 11 的文档,但是 the release notes for Clang-Tidy 12不要把它列为新的,所以它看起来像是在 11 中添加的。

关于c - 什么是 "Clang-Tidy: Function is within a recursive call chain"?如何解决?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63939799/

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