搜索没让我找到答案,不过很可能 ziglings 里讲过,只是我给忘了。
我在 Zig 0.17.0 中通过 translate_c 引入作为系统库的 Vulkan。生成的声明是这样的。
pub extern fn vkEnumeratePhysicalDevices(instance: VkInstance, pPhysicalDeviceCount: [*c]u32, pPhysicalDevices: [*c]VkPhysicalDevice) VkResult;
我不明白 [*c] 的含义。这只是说它应该指向数组的第一个元素吗?
下面的写法终于能编译了,不过我怀疑有更常用的写法。
var adapters = try allocator.alloc(vulkan.VkPhysicalDevice, adapter_count);
_ = vulkan.vkEnumeratePhysicalDevices(instance, &adapter_count,
@ptrCast(&adapters[0]));
先谢谢愿意指点的人!
从英语翻译·查看原文Searching hasn't turned up an answer for me, although this may well have appeared in ziglings and slipped my memory.
I'm bringing in Vulkan as a system library using translate_c on Zig 0.17.0. The resulting declaration looks like this:
pub extern fn vkEnumeratePhysicalDevices(instance: VkInstance, pPhysicalDeviceCount: [*c]u32, pPhysicalDevices: [*c]VkPhysicalDevice) VkResult;
What puzzles me is the meaning of [*c]. Does it merely say this should point at an array's initial element?
The following finally compiled for me, although I suspect there's a more conventional way to write it.
var adapters = try allocator.alloc(vulkan.VkPhysicalDevice, adapter_count);
_ = vulkan.vkEnumeratePhysicalDevices(instance, &adapter_count,
@ptrCast(&adapters[0]));
Thanks beforehand for any pointers!