gpt4 book ai didi

c - 用于检测字符串文字连接的 gcc 标志?

转载 作者:太空狗 更新时间:2023-10-29 15:08:02 24 4
gpt4 key购买 nike

我最近修复了一个错误,该错误是由类似的东西导致的

const char *arr[] = {
"string1", //some comment
"string2",
"string3" //another comment
"string4",
"string5"
};

即有人忘记了 , 在“string3”和“string3”和“string4”粘贴在一起之后。现在,虽然这是完全合法的代码,但是否有 gcc 警告标志或其他可以扫描代码库以查找类似错误的工具?

最佳答案

您可以使用的基本“工具”是预处理器 hack,但这是一个非常丑陋的解决方案:

#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));
}

关于c - 用于检测字符串文字连接的 gcc 标志?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28744208/

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