我的代码中有以下内容,RDMPacket
是在包含的头文件中定义的结构。前3个缓冲区指针(DMX缓冲区)工作正常,但第2个3(RDM缓冲区)工作不正常。我做错什么了吗?否则我如何引用一组带有指针的结构?
uint8_t dmxRxBufA[NumberOfChannels];
uint8_t dmxRxBufB[NumberOfChannels];
uint8_t dmxRxBufC[NumberOfChannels];
uint8_t *pDMXWriteBuf = dmxRxBufA;
uint8_t *pDMXSpareBuf = dmxRxBufB;
uint8_t *pDMXReadBuf = dmxRxBufC;
RDMPacket rdmRxBufA;
RDMPacket rdmRxBufB;
RDMPacket rdmRxBufC;
RDMPacket *pRDMWriteBuf = rdmRxBufA;
RDMPacket *pRDMSpareBuf = rdmRxBufB;
RDMPacket *pRDMReadBuf = rdmRxBufC;
uart.c:90:27: error: incompatible types when initializing type 'struct RDMPacket *' using type 'RDMPacket'
uart.c:91:27: error: incompatible types when initializing type 'struct RDMPacket *' using type 'RDMPacket'
uart.c:92:26: error: incompatible types when initializing type 'struct RDMPacket *' using type 'RDMPacket'
最佳答案
前三个是uint8_t
数组。这意味着dmxRxBuf是指向第一个元素的指针,因此,auint8_t*
其他元素只是RDMPacket
。如果你想传递他们的地址,你可以使用这个:
RDMPacket *pRDMWriteBuf = &rdmRxBufA;
RDMPacket *pRDMSpareBuf = &rdmRxBufB;
RDMPacket *pRDMReadBuf = &rdmRxBufC;
或者创建
RDMPacket
数组,就像对uint8所做的那样RDMPacket rdmRxBufA[];
RDMPacket rdmRxBufB[];
RDMPacket rdmRxBufC[];