我应该向这个函数发送什么参数
What arguments should I send to this function
我有一个 C 函数:
* \fn int32_t readMyData(uint8_t *dStatus, uint8_t *dData, uint8_t *dCRC)
* \param *dStatus pointer to address where STATUS byte will be stored
* \param *dData pointer to starting address where data bytes will be stored
* \param *dCRC pointer to address where CRC byte will be stored
* \return 32-bit sign-extended conversion result (data only)
int32_t readMyData(uint8_t status[], uint8_t data[], uint8_t crc[])
我不习惯指针,你能帮我吗,我应该在我的Main函数中初始化什么样的变量才能调用readMyData?在原型的参数中它是 Arrays: uint8_t status[], uint8_t data[], uint8_t crc[] 但在函数的注释中它指向:dStatus pointer to address .
我应该定义:
uint8_t *status, *data, *crc
int32_t result =0;
然后调用函数;
result = readMyData(&status,&data,&crc);
有道理吗?
谢谢
如果 documentation/specification 声明参数是指针,那么应该使用指针而不是数组声明(尽管不是错误而是语义)。
因此您的函数原型在文档中应如下所示:
int32_t readMyData(uint8_t *dStatus, uint8_t *dData, uint8_t *dCRC);
此外,参数说明指出,这些是指向特定数据将存储的地址的指针,因此如果您想调用该函数,您必须provide/define 即 存储.
例如
uint8_t dStatus; //single byte, no array needed
uint8_t dData[NUM_DATA]; //NUM_DATA some arbitrary number
uint8_t dCRC[NUM_CRC]; //NUM_CRC some arbitrary number
//invoke
int32_t result = readMyData(
&dStatus /* usage of address of operator */,
dData /* no usage of & needed, array decays to pointer */,
dCRC /* same as dData */
);
数组到指针转换的更多信息:
我有一个 C 函数:
* \fn int32_t readMyData(uint8_t *dStatus, uint8_t *dData, uint8_t *dCRC)
* \param *dStatus pointer to address where STATUS byte will be stored
* \param *dData pointer to starting address where data bytes will be stored
* \param *dCRC pointer to address where CRC byte will be stored
* \return 32-bit sign-extended conversion result (data only)
int32_t readMyData(uint8_t status[], uint8_t data[], uint8_t crc[])
我不习惯指针,你能帮我吗,我应该在我的Main函数中初始化什么样的变量才能调用readMyData?在原型的参数中它是 Arrays: uint8_t status[], uint8_t data[], uint8_t crc[] 但在函数的注释中它指向:dStatus pointer to address .
我应该定义:
uint8_t *status, *data, *crc
int32_t result =0;
然后调用函数;
result = readMyData(&status,&data,&crc);
有道理吗?
谢谢
如果 documentation/specification 声明参数是指针,那么应该使用指针而不是数组声明(尽管不是错误而是语义)。
因此您的函数原型在文档中应如下所示:
int32_t readMyData(uint8_t *dStatus, uint8_t *dData, uint8_t *dCRC);
此外,参数说明指出,这些是指向特定数据将存储的地址的指针,因此如果您想调用该函数,您必须provide/define 即 存储.
例如
uint8_t dStatus; //single byte, no array needed
uint8_t dData[NUM_DATA]; //NUM_DATA some arbitrary number
uint8_t dCRC[NUM_CRC]; //NUM_CRC some arbitrary number
//invoke
int32_t result = readMyData(
&dStatus /* usage of address of operator */,
dData /* no usage of & needed, array decays to pointer */,
dCRC /* same as dData */
);
数组到指针转换的更多信息: