This seems to be as close as I can get it to my style. I'd've wanted to also set Cpp11BracedListStyle[1] to Block, but that ended up misformatting some compound literals that included expressions with binary operators. I'm also unsure what is going on with the formatting of _Generic(). [1] https://clang.llvm.org/docs/ClangFormatStyleOptions.html#cpp11bracedliststyle
58 lines
1.4 KiB
C
58 lines
1.4 KiB
C
// This header file includes the type / type macro definitions for
|
|
// vectors and spans needed by other headers.
|
|
|
|
#ifndef CUSEL_VECTOR_INTERNAL_H
|
|
#define CUSEL_VECTOR_INTERNAL_H
|
|
|
|
// For size_t
|
|
#include <stddef.h>
|
|
|
|
// ------------------------------------------------------------
|
|
// 1. Vectors (growable owning array type)
|
|
// ------------------------------------------------------------
|
|
|
|
struct type_erased_vector {
|
|
// Put the size_t fields first, so that dummy_pointer will alias
|
|
// them and more likely trigger a segfault if we accidentally use
|
|
// it.
|
|
size_t capacity;
|
|
size_t size;
|
|
void *ptr;
|
|
};
|
|
|
|
#define VEC(type) vec_##type
|
|
|
|
#define DECL_VEC(type) \
|
|
typedef struct { \
|
|
union { \
|
|
struct type_erased_vector data; \
|
|
type *dummy_pointer; \
|
|
}; \
|
|
} VEC(type)
|
|
|
|
// ------------------------------------------------------------
|
|
// 2. Spans (borrowing subslice-of-array type)
|
|
// ------------------------------------------------------------
|
|
|
|
struct type_erased_span {
|
|
size_t size;
|
|
void *ptr;
|
|
};
|
|
|
|
#define SPAN(type) span_##type
|
|
|
|
#define DECL_SPAN(type) \
|
|
typedef struct { \
|
|
union { \
|
|
struct type_erased_span data; \
|
|
type *dummy_pointer; \
|
|
}; \
|
|
} SPAN(type)
|
|
|
|
// ------------------------------------------------------------
|
|
// 3. Declarations for vectors/spans of basic types
|
|
// ------------------------------------------------------------
|
|
DECL_VEC(char);
|
|
DECL_SPAN(char);
|
|
|
|
#endif
|