Vulkan makes extensive use of structs in its functions for passing lots of arguments, and enabling extensions by daisy-chaining these structs together by using a structure type and "next" pointer as the first two members of each struct. For example, take this function:
VkResult vkCreateInstance(
const VkInstanceCreateInfo* pCreateInfo,
const VkAllocationCallbacks* pAllocator,
VkInstance* pInstance);
Description of VkInstanceCreateInfo
:
typedef struct VkInstanceCreateInfo {
VkStructureType sType;
const void* pNext;
VkInstanceCreateFlags flags;
const VkApplicationInfo* pApplicationInfo;
uint32_t enabledLayerCount;
const char* const* ppEnabledLayerNames;
uint32_t enabledExtensionCount;
const char* const* ppEnabledExtensionNames;
What intrigues me about this is that, from what I can tell, the packaging of struct members is at the discretion of the compiler (except for the ordering, which is not). This would be in contrast to a COM-based API which does not suffer from compiler-dependent issues, as far as I know. I've been looking through the Vulkan headers expecting to find compiler-specific alignment pragmas/statements, but nothing stands out.
Looking at pages like the data structure alignment Wikipedia page would suggest that the common, well-known compilers follow certain rules on x86:
The type of each member of the structure usually has a default alignment, meaning that it will, unless otherwise requested by the programmer, be aligned on a pre-determined boundary. The following typical alignments are valid for compilers from Microsoft (Visual C++), Borland/CodeGear (C++Builder), Digital Mars (DMC), and GNU (GCC) when compiling for 32-bit x86...
but the use of weasel words like "usually" and "typical" makes it unreliable to me. A paragraph from this SO answer is more compelling:
IMPORTANT NOTE: Both the C and C++ standards state that structure alignment is implementation-defined. Therefore each compiler may choose to align data differently, resulting in different and incompatible data layouts. For this reason, when dealing with libraries that will be used by different compilers, it is important to understand how the compilers align data. Some compilers have command-line settings and/or special #pragma statements to change the structure alignment settings.
If I'm using the Vulkan SDK compiled by one compiler with one set of rules, and I'm writing a client application using another compiler, isn't there the potential for alignment problems? What am I missing here?