C 质量分析与控制
我已经为我的代码库运行了质量分析控制,我对看到的一些错误值有一些疑问,如下所示: 这只是代码摘录C 质量分析与控制,c,C,我已经为我的代码库运行了质量分析控制,我对看到的一些错误值有一些疑问,如下所示: 这只是代码摘录 typedef struct UISR_caller_info_s/*structure declaration*/ { unsigned char number[20]; unsigned char Name[30]; unsigned int numberType; } caller_t; static ca
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>
2027:strcpy((char*)gs_val.Name,空);
^
Msg(2:0310)转换为不同的对象指针类型。
参考-ISO:C90-6.3.4强制转换运算符-语义
错误显示在char*typecasting上,我真的不知道为什么会发生这种情况。
请让我知道如何避免这种错误
谢谢
GNR首先,
strcpy
调用可能会导致分段错误(并且肯定会导致未定义的行为)-您可能不希望第二个参数为NULL
。无论如何,您的通话不需要演员阵容:
strcpy(gs_value.Name, "");
会很好的,这可能就是你最初的意思。这可能是因为你的编译器非常挑剔,它抱怨从
无符号字符
到字符
的转换-你可以通过适当地更改结构来解决这个问题。@Carl…我已经试过了,但在运行QAC时我发现了同样的错误repeating@carl...When我试过了(void*)打字效果很好,不知道怎么做happenned@Maddy-如果您的strcpy
中有NULL
,则调用它肯定不起作用。