vulkan/util: Make STACK_ARRAY() C++-friendly
authorBoris Brezillon <boris.brezillon@collabora.com>
Fri, 1 Apr 2022 14:16:56 +0000 (07:16 -0700)
committerMarge Bot <emma+marge@anholt.net>
Fri, 8 Apr 2022 11:54:44 +0000 (11:54 +0000)
C++ doesn't like the {0} initializer pattern when the first
field is not an integer, let's use the {} when __cplusplus is
defined.

Reviewed-by: Jason Ekstrand <jason.ekstrand@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15698>

src/vulkan/util/vk_util.h

index 019ab5b..7a33e77 100644 (file)
@@ -278,8 +278,14 @@ vk_spec_info_to_nir_spirv(const VkSpecializationInfo *spec_info,
 
 #define STACK_ARRAY_SIZE 8
 
+#ifdef __cplusplus
+#define STACK_ARRAY_ZERO_INIT {}
+#else
+#define STACK_ARRAY_ZERO_INIT {0}
+#endif
+
 #define STACK_ARRAY(type, name, size) \
-   type _stack_##name[STACK_ARRAY_SIZE] = {0}; \
+   type _stack_##name[STACK_ARRAY_SIZE] = STACK_ARRAY_ZERO_INIT; \
    type *const name = \
      ((size) <= STACK_ARRAY_SIZE ? _stack_##name : (type *)malloc((size) * sizeof(type)))