可能的警告解决方案

时间:2010-05-12 14:33:49

标签: c eclipse

我有一个非常大的代码,这就是为什么我不能在这里发布我的所有代码,有人可以解释如果我有错误incompatible pointer type可能会有什么问题,并给我几种方法来解决它,谢谢提前

只是一点点澄清:我正在使用函数指针

ptrLine createBasicLine(){
    DECLARE_RESULT_ALLOCATE_AND_CHECK(ptrLine, Line);
    result->callsHistory = listCreate(copyCall,destroyCall);          <-here
    result->messagesHistory = listCreate(copyMessage,destroyMessage); <-and here
    result->linesFeature = NULL;
    result->strNumber = NULL;
    result->lastBill = 0;
    result->lineType = MTM_REGULAR_LINE;
    result->nCallTime = 0;
    result->nMessages = 0;
    result->rateForCalls = 0;
    result->rateForMessage = 0;
    return result;
}

copyCall,destroyCall - 指向函数的指针

/**
 * Allocates a new List. The list starts empty.
 *
 * @param copyElement
 *  Function pointer to be used for copying elements into the list or when
 *  copying the list.
 * @param freeElement
 *  Function pointer to be used for removing elements from the list
 * @return
 *  NULL - if one of the parameters is NULL or allocations failed.
 *  A new List in case of success.
 */
List listCreate(CopyListElement copyElement, FreeListElement freeElement);

函数的定义

ptrCall (*createCall)() = createNumberContainer;

void (*destroyCall)(ptrCall) = destroyNumberContainer;

ptrCall (*copyCall)(ptrCall) = copyNumberContainer;

1 个答案:

答案 0 :(得分:2)

我认为你正在使用的指针对于你试图使用它的某些上下文是一种不兼容的类型。

  1. 在该上下文中停止使用指针。
  2. 使用其他指针。
  3. 更改上下文以与指针类型兼容。
  4. 将指针强制转换为上下文的兼容类型。
  5. 其中,最后一个可能看起来最具吸引力,因为它很可能会让你快速通过编译器。可悲的是,它可能会使您的代码无法以奇怪和不可预测的方式工作。