2014-06-10 60 views
-2
_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; 
} 

任何數據,我得到這個錯誤而編譯:沒有得到中的sprintf

Left operand of . has incompatible type 'pointer to COMMAND_DESCRIPTOR'. 

回答

0

,因爲你正在傳遞一個指向COMMAND_DESCRIPTOR(這是一個結構我想),以賦值結構的字段,你需要對其進行解引用。
因此,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; 
}