Matthew Tipton Matthew Tipton - 1 month ago 20
C# Question

How to marshall struct defined from macros in C header?

I have NO idea hot to marshall the next part of Vulkan API header file for C# use:

#define VK_DEFINE_HANDLE(object) typedef struct object##_T* object;
...
VK_DEFINE_HANDLE(VkInstance)


I need to use in this method later:

VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance(
const VkInstanceCreateInfo* pCreateInfo,
const VkAllocationCallbacks* pAllocator,
VkInstance* pInstance
);


Pointer to
vkInstance
, okay. But, what is this magic stuff:
typedef struct object##_T* object;
in macros-style (preprocessor)?

Answer

The ## is the concatenate operator in the C++ pre-processor - so in the above example

#define VK_DEFINE_HANDLE(object) typedef struct object##_T* object;
VK_DEFINE_HANDLE(VkInstance)

would expand out to

typedef struct VkInstance_T* VkInstance;