[英]What does the following C code do, = { }
The code below is contained in STMicroelectronics C code for a USB driver.下面的代码包含在 USB 驱动程序的 STMicroelectronics C 代码中。 I am trying to follow (understand) how this works, and I admit my C programming is not strong.
我试图遵循(理解)这是如何工作的,我承认我的 C 编程并不强。
My question is what does / is我的问题是/是什么
USBD_Interface_fops_FS =
{ xxxxx }
??? ???
I cannot find in K & R, where the "=" assignment operator is used in a similar example.我在 K & R 中找不到,在类似的示例中使用了“=”赋值运算符。
typedef struct _USBD_CDC_Itf
{
int8_t (* Init) (void);
int8_t (* DeInit) (void);
int8_t (* Control) (uint8_t, uint8_t * , uint16_t);
int8_t (* Receive) (uint8_t *, uint32_t *);
}USBD_CDC_ItfTypeDef;
static int8_t CDC_Init_FS (void);
static int8_t CDC_DeInit_FS (void);
static int8_t CDC_Control_FS (uint8_t cmd, uint8_t* pbuf, uint16_t length);
static int8_t CDC_Receive_FS (uint8_t* pbuf, uint32_t *Len);
USBD_CDC_ItfTypeDef USBD_Interface_fops_FS =
{
CDC_Init_FS,
CDC_DeInit_FS,
CDC_Control_FS,
CDC_Receive_FS
};
It's struct initializer syntax .它是结构初始化语法。 It's just setting the four function pointers in the struct to the four named functions.
它只是将结构中的四个函数指针设置为四个命名函数。
Struct initialization.结构初始化。
This:这个:
USBD_CDC_ItfTypeDef USBD_Interface_fops_FS =
{
CDC_Init_FS,
CDC_DeInit_FS,
CDC_Control_FS,
CDC_Receive_FS
};
is just a more efficient way of doing this:只是一种更有效的方法:
USBD_CDC_ItfTypeDef USBD_Interface_fops_FS;
USBD_Interface_fops_FS.Init = CDC_Init_FS;
USBD_Interface_fops_FS.DeInit = CDC_DeInit_FS;
USBD_Interface_fops_FS.Control = CDC_Control_FS;
USBD_Interface_fops_FS.Receive = CDC_Receive_FS;
I know for sure that this has been around since ANSI C 89. I don't know if they had struct initialization in K & R though...我确信这自 ANSI C 89 以来就已经存在了。我不知道他们是否在 K & R 中进行了结构初始化...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.