_export int DSPCmdOut(COMMAND_DESCRIPTOR *cmd)
{
cmd.u[0] = CMD_SG_SYNCHED;
cmd.u[1] = uThisStation;
cmd.u[2] = iMode;
DSPCmdOut(&cmd);
return 0;
}
_export int DSPCmdOut(COMMAND_DESCRIPTOR *cmd)
{
if(S->uCMD > (MAX_CMD-1))
return -1;
S->cmd[S->uCMD] = *cmd;
S->uCMD++;
sprintf (cLogLine, "%u,%u,%u: cmd data", cmd.u[0],cmd.u[1],cmd.u[2]);
WriteLine (uhGDSLogFile, cLogLine, strlen(cLogLine));
return 0;
}
我在编译时遇到了这个错误:
Left operand of . has incompatible type 'pointer to COMMAND_DESCRIPTOR'.
答案 0 :(得分:0)
因为你要将一个指针传递给COMMAND_DESCRIPTOR
(这是我假设的一个结构),以便为struct的字段赋值,你需要取消引用它。
所以,cmd->u[0]
语法只是(*cmd).u[0]
。 ->
只是一种语法糖。
将cmd.u[0] = CMD_SG_SYNCHED;
更改为cmd->u[0] = CMD_SG_SYNCHED;
,依此类推。
这是一个很好的主题:What is the difference between the dot (.) operator and -> in C++?
您的完整代码应如下所示:
_export int DSPCmdOut(COMMAND_DESCRIPTOR *cmd)
{
cmd->u[0] = CMD_SG_SYNCHED;
cmd->u[1] = uThisStation;
cmd->u[2] = iMode;
DSPCmdOut(&cmd);
return 0;
}
_export int DSPCmdOut(COMMAND_DESCRIPTOR *cmd)
{
if(S->uCMD > (MAX_CMD-1))
return -1;
S->cmd[S->uCMD] = *cmd;
S->uCMD++;
sprintf (cLogLine, "%u,%u,%u: cmd data", cmd->u[0],cmd->u[1],cmd->u[2]);
WriteLine (uhGDSLogFile, cLogLine, strlen(cLogLine));
return 0;
}