clang语法检查设置
使用clang进行语法检查非常方便,不用像pclint那样需要一大堆的配置。控制台命令如下:
~$ clang -fsyntax-only file.c
./file.c:454:27: warning: passing 'char [87]' to parameter of type 'UINT8 *' (aka 'unsigned char *') converts between pointers to integer types with different sign [-Wpointer-sign]
SQLLog(LOG_EBASE, "[REPT ] GetSmsOfReportOverTime: delete from xbase error! "
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./report.h:318:30: note: passing argument to parameter 'pMsg' here
void SQLLog(int type, UINT8 *pMsg, ...);
如果需要include头文件文件夹,这个和gcc一样,使用-I
包含文件夹。在老代码中,常常出现无符号和符号变量之间的转换,报错非常多,逐一修改麻烦,这时可以在clang语法检查中禁用。禁用语法如下:
// 在文件开始添加禁用的语法检查类型
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-field-initializers"
#pragma clang diagnostic ignored "-Wmissing-braces"
#pragma clang diagnostic ignored "-Wpointer-sign"
...
// 文件结尾还原
#pragma clang diagnostic pop