[英]What arguments should I send to this function
I have a C 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[])
I am not used to pointer, could you help me, what kind of variables should I initialize in my Main function to be able to to call readMyData?我不习惯指针,你能帮我,我应该在我的 Main 函数中初始化什么样的变量才能调用 readMyData? In the arguments of the prototype it is Arrays: uint8_t status[], uint8_t data[], uint8_t crc[] but in the comments of the function it pointers: dStatus pointer to address.在原型的参数中,它是数组:uint8_t status[], uint8_t data[], uint8_t crc[] 但在函数的注释中它指向: dStatus 指向地址的指针。
Should I define:我应该定义:
uint8_t *status, *data, *crc
int32_t result =0;
Then call the function;然后调用函数;
result = readMyData(&status,&data,&crc);
Does it makes sense?有道理吗?
Thank you谢谢
If the documentation/specification states that the arguments are pointers, then pointer and not array declaration should be used (although not an error but semantics).如果文档/规范指出参数是指针,则应使用指针而不是数组声明(尽管不是错误而是语义)。
So your function prototype should look like in the documentation:所以你的函数原型应该在文档中看起来像:
int32_t readMyData(uint8_t *dStatus, uint8_t *dData, uint8_t *dCRC);
Further, the description for the arguments states, that these are pointers to addresses where the specific data will be stored , so if you want to call that function, you have to provide/define that storage .此外,参数的描述指出,这些是指向将存储特定数据的地址的指针,因此如果您想调用该函数,您必须提供/定义该存储。
eg例如
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 */
);
enter code here
Thank you very much Erdal, Weird that the documentation gives: enter code here
非常感谢 Erdal,文档给出的奇怪之处:
* \fn int32_t readData(uint8_t *dStatus, uint8_t *dData, uint8_t *dCRC)
but the function prototype and the function are :但函数原型和函数是:
int32_t readData(uint8_t status[], uint8_t data[], uint8_t crc[]);
So if I don't want to change anything in the library and the function, I would need to send Arrays:因此,如果我不想更改库和函数中的任何内容,则需要发送数组:
uint8_t dStatus[1]; //single byte, no array needed
uint8_t dData[10]; //NUM_DATA some arbitrary number
uint8_t dCRC[4]; //NUM_CRC some arbitrary number
//invoke
int32_t result = readMyData(dStatus,dData,dCRC);
Is it ok?可以吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.