我想创建一个嵌套函数的结构,它将结构本身作为参数传递到嵌套函数以简化调用函数。代码将使用xc16编译器在Pic 24f系列单片机上运行。另外,我知道计数函数是多余的,但我认为这说明了我的观点。例如:c结构自身作为参数传递到指针函数
结构:
typedef struct
{
uchar Fifo[UART1_RX_MAX_BUFFER_SIZE];
uchar FifoIndex = 0;
uchar FifoCount = 0;
uchar FifoOverrunFlag = FALSE;
uchar (*CountPointer);
uchar (*PutPointer);
}Fifo;
功能:
// Returns: The number of items in the Fifo
uchar FifoGetCount(Fifo *fifo)
{
return fifo->FifoCount;
}
// Summary: Adds data to the end of the Fifo
// Parameters:
// data: Data to be added to the end of the Fifo
// Returns: True (1) if the data was successfully added
// False (0) if the data was not successfully added
// as a result of the Fifo being full
uchar FifoPut(Fifo *fifo, uchar data)
{
if (fifo->FifoCount > FIFO_MAX_SIZE)
{
fifo->FifoOverrunFlag = TRUE;
return FALSE;
}
uint putIndex = fifo->FifoGetPutIndex();
fifo->Fifo[putIndex] = data;
fifo->FifoCount++;
return TRUE;
}
主营:
Fifo fifo1;
int main()
{
fifo1.CountPointer = FifoGetCount(fifo1);
fifo1.PutPointer = FifoPut(fifo1, uchar data);
// Intended Usage
uchar myCount = fifo1.FifoGetCount();
uchar myData = 1;
fifo1.FifoPut(myData);
}
谢谢,我正在寻找什么。代码有点混乱是剥离了一些代码的结果,因此忽略了编译器问题。 – user2419860