2011-11-20 524 views
2

這是我需要修改的C中的函數。我想從「box」開始的前4個字節的地址與從rt_tsk_self()返回的U32值進行比較,但它只是給了我「錯誤必須是指向完整對象類型的指針」的錯誤。錯誤:表達式必須是指向完整對象類型的指針(?)

/*--------------------------- rt_free_box -----------------------------------*/ 

int rt_free_box (void *box_mem, void *box) { 
    /* Free a memory block, returns 0 if OK, 1 if box does not belong to box_mem */ 
if !(defined(__TARGET_ARCH_7_M) || defined(__TARGET_ARCH_7E_M)) 
    int irq_dis; 
endif 

    if (box < box_mem || box > ((P_BM) box_mem)->end) { 
    return (1); 
    } 

    //MODIFIED*********** 
    if (*(box-4) != rt_tsk_self()) { //<--- error: #852: expression must be a pointer to a complete object type 
    return (1); 
    } 
    //*************** 

/* 
other unrelated code 
*/ 
    return (0); 
} 

回答

2

您試圖取消引用void *。這是行不通的。試試這個:

if (*(((uint32_t *)box)-1) != rt_tsk_self()) { 
+0

+1使用一個大小爲4對象的很好的做到這一點:) – Mordachai

+0

迂腐注:如果得到的指針確實指向一個'uint32_t'只有明確定義,這是嚴格來說。你沒有受到保護,不受虐待;程序的正確性取決於參數的*值*。 –

相關問題