我有以下内容:
static unsigned int *tick = NULL;
...
if (tick == NULL)
tick = calloc(MAX_PORT,sizeof(unsigned int));
...
Run Code Online (Sandbox Code Playgroud)
功能上按预期工作,但覆盖率抱怨: 解析警告(PW.INCOMPATIBLE_ASSIGNMENT_OPERANDS)1.incompatible_assignment_operands:类型"int"的值不能分配给"unsigned int*"类型的实体, 我不完全理解为什么
错误消息表明Coverity认为calloc返回一个int,如果你没有包含,则会发生这种情况stdlib.h(对于calloc)较旧的C.但是现代C中不允许这样做(即,C99及以上版本中不允许隐式声明).