我已经对我的代码库运行了质量分析控制,并且我对看到的一些错误值有一些疑问,如下所示:
这只是代码摘录
typedef struct UISR_caller_info_s/*structure declaration*/
{
unsigned char number[20];
unsigned char Name[30];
unsigned int numberType;
} caller_t;
static caller_t gs_val;/*variable of the structure type*/
错误:
2027: strcpy((char *)gs_val.Name, NULL);
^
Msg(2:0310) Casting to different object pointer type.
REFERENCE - ISO:C90-6.3.4 Cast Operators - Semantics <next>
错误显示在 char * 类型转换中,我真的不知道为什么会发生这种情况。 请告诉我如何避免此类错误
谢谢 GNR
最佳答案
首先,strcpy
调用可能会导致段错误(并且肯定会导致未定义的行为) - 您可能不希望 NULL
code> 作为第二个参数。无论如何,您的通话不需要 Actor 阵容:
strcpy(gs_value.Name, "");
可以正常工作,这可能就是您最初的意思。您的编译器可能非常挑剔,并且它提示从 unsigned char
到 char
的转换 - 您可以通过更改您的结构适当。
关于c - 质量分析控制疑点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6946245/