在通过 PCIe 驱动程序时,我看到了这种类型的结构数组初始化
static struct pci_device_id DWC_ETH_QOS_id[] = {
{ PCI_DEVICE(VENDOR_ID, DEVICE_ID), },
{ },
}
我在设备树 of_device_id 初始化器中也发现了类似的代码:
static const struct of_device_id rh850_match_table[] = {
{ .compatible = "renesas,rh850" },
{ }
};
为什么末尾有一个空的{}?
感谢您的帮助!
最佳答案
正如@underscore_d 所指出的,{} 被添加为标记元素,以便循环遍历这些数组的代码知道何时停止。它依赖于最后一个“空”哨兵元素作为终止条件。
依赖哨兵元素的代码:
结构 of_device_id 表: https://elixir.bootlin.com/linux/v4.14.76/source/drivers/of/base.c#L997
结构 pci_device_id: https://elixir.bootlin.com/linux/v2.6.35/source/drivers/pci/pci-driver.c#L246
关于C - 结构数组初始化中空终止符的含义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52796221/