lufa中的设备描述符...这是什么样的结构(内部)?我认为这没什么具体的,只是向 C/C++ 提出的问题。程序员
我正在一个项目中使用 LUFA ,在阅读了一些示例后,我看到了其中一些构造。这些是宏吗?我知道 AVR 设备并且知道 PROGMEM 是其中之一?但什么是 .Header 以及为什么它以“.”开头。
有人可以向我解释如何创建这样的结构,或者告诉我在 LUFA 文档中哪里可以找到它们吗?
USB_Descriptor_Device_t PROGMEM DeviceDescriptor =
{
.Header = {.Size = sizeof(USB_Descriptor_Device_t), .Type = DTYPE_Device},
.USBSpecification = VERSION_BCD(01.10),
.Class = USB_CSCP_NoDeviceClass,
.SubClass = USB_CSCP_NoDeviceSubclass,
.Protocol = USB_CSCP_NoDeviceProtocol,
.Endpoint0Size = FIXED_CONTROL_ENDPOINT_SIZE,
.VendorID = 0x03EB,
.ProductID = 0x2045,
.ReleaseNumber = VERSION_BCD(00.01),
.ManufacturerStrIndex = 0x01,
.ProductStrIndex = 0x02,
.SerialNumStrIndex = USE_INTERNAL_SERIAL,
.NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS
};
I am using LUFA for a project and after reading some of the examples I saw some of these constructs. Are these macros? I know AVR devices and know that PROGMEM is one? But what is .Header and why is it starting with a ".".
Can someone explain to me how to create contructs like these or show me where I will find them in the LUFA documentation?
USB_Descriptor_Device_t PROGMEM DeviceDescriptor =
{
.Header = {.Size = sizeof(USB_Descriptor_Device_t), .Type = DTYPE_Device},
.USBSpecification = VERSION_BCD(01.10),
.Class = USB_CSCP_NoDeviceClass,
.SubClass = USB_CSCP_NoDeviceSubclass,
.Protocol = USB_CSCP_NoDeviceProtocol,
.Endpoint0Size = FIXED_CONTROL_ENDPOINT_SIZE,
.VendorID = 0x03EB,
.ProductID = 0x2045,
.ReleaseNumber = VERSION_BCD(00.01),
.ManufacturerStrIndex = 0x01,
.ProductStrIndex = 0x02,
.SerialNumStrIndex = USE_INTERNAL_SERIAL,
.NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是命名结构体成员的 C99 方式,因此您可以按任意顺序给出值。我相信这个术语是“指定的初始化程序”。不是 C++ 的一部分。
That is a C99 way of naming members of a struct, so you can give the values in an arbitrary order. I believe the term is "designated initializers". Not part of C++.
作为 Bo Persson 说,这是初始化结构体的 C99 方式。
USB_Descriptor_Device_t
表示Header
字段是USB_Descriptor_Header_t
。如果您要处理的话,您可能应该阅读一下指定的初始化程序 C99 代码。您可以将您的代码片段翻译为:
我认为在这种情况下显式初始化更容易阅读,但指定的初始化程序确实有其用途。
As Bo Persson said, this is the C99 way of initializing a struct. The LUFA documentation for
USB_Descriptor_Device_t
says that theHeader
field is aUSB_Descriptor_Header_t
.You should probably read up on designated initializers a little if you are going to be dealing with C99 code. You can translate your snippet into:
I think that explicit initialization is easier to read in this case, but designated initializers do have their uses.