使用sizeof实现一个函数

时间:2016-07-14 07:46:06

标签: c

我是C编程和使用特定库的新手。我需要使用这个功能:

le_result_t le_ecall_ExportMsd ( le_ecall_CallRef_t     ecallRef,
                                 uint8_t *              msdPtr,
                                 size_t *               msdNumElementsPtr 
                                )

参数:

[in] ecallRef                   eCall reference
[out] msdPtr                    the encoded MSD
[in,out] msdNumElementsPtr  

为了获得que编码的MSD,我开发了这段代码(稍微简化了一点):

static le_ecall_CallRef_t    LastTestECallRef = NULL;
uint8_t msd[] = NULL;

void StarteCall (void)
{
    le_ecall_ExportMsd(LastTestECallRef, msd, sizeof(msd));
}

sizeof返回size_t,我需要size_t *所以我收到以下错误:

expected 'size_t *' but argument is of type 'unsigned int'  

如果有人能帮助我,我将不胜感激。

1 个答案:

答案 0 :(得分:4)

您需要传递最后一个参数的指针,如下所示:

size_t nsize = sizeof(msd);
le_ecall_ExportMsd(LastTestECallRef, msd, &nsize);

原因是因为函数定义需要size_t *msdNumElementsPtr这是一个指针,而不是size_t msdNumElementsPtr