将struct成员传递给c中的函数

我在下面定义了一个struct ,用于通过uart发送的帧的内容。

结构的最后一个成员是一个帧校验序列(fsc),它被计算为struct成员(len,cmd0,cmd1和data)中所有字节的XOR。 我有一个函数来计算下面的fsc。

我的问题是,如何将struct成员传递给在calcFCS()中调用的build_uart_frame()

非常感谢

 typedef struct uart_frame { uint8_t sof; /* 1 byte */ uint8_t len; /* 1 bytes */ uint8_t cmd0; /* 1 byte */ uint8_t cmd1; char data[11]; /* 0 -250 byte */ unsigned char fcs; /* 1 byte */ } uart_frame_t; //------------------------------------------------------------------------- // Global uart frame uart_frame_t rdata; //------------------------------------------------------------------------- unsigned char calcFCS(unsigned char *pMsg, unsigned char len) { unsigned char result = 0; while(len--) { result ^= *pMsg++; } return(result); } //------------------------------------------------------------------------- // Worker code to populate the frame int build_uart_frame() { uart_frame_t *rd = &rdata; //pointer variable 'rd' of type uart_frame // common header codes rd->sof = 0xFE; rd->len = 11; rd->cmd0 = 0x22; rd->cmd0 = 0x05; snprintf(rd->data, sizeof(rd->data), "%s", "Hello World"); rd->fcs = calcFCS(?) return 0; } 

正如你所说

帧校验序列(fsc),计算为struct成员中所有字节的XOR(len,cmd0,cmd1和data)

不是单独传递所有成员,而是将指针传递给struct uart_frame

所以你的function的签名应该是

unsigned char calcFCS(uart_frame * frame)