我最近修复了一个类似的结果的错误
const char *arr[] = {
"string1", //some comment
"string2",
"string3" //another comment
"string4",
"string5"
};
Run Code Online (Sandbox Code Playgroud)
即有人忘记了一个,在"string3"之后,"string3"和"string4"被粘贴在一起.现在,虽然这是完全合法的代码,是否有gcc警告标志,或其他工具可以扫描代码库中的类似错误?
您可以使用的基本“工具”是预处理器黑客,但这是一个非常丑陋的解决方案:
#include <stdlib.h>
#include <stdio.h>
int start = __LINE__;
const char *arr[] = {
"string1", //some comment
"string2",
"string3" //another comment
"string4",
"string5"
};int end = __LINE__;
int main(int argc, char **argv){
printf("arr length: %zu\n", sizeof(arr) / sizeof(arr[0]));
printf("_assumed_ arr length: %d\n", (end - start - 2));
}
Run Code Online (Sandbox Code Playgroud)