From 4227c0d62e6df83e96c2b5fa62a8a743d4d96c8f Mon Sep 17 00:00:00 2001 From: lonkaars Date: Sun, 29 May 2022 19:41:16 +0200 Subject: funky pointer magic to optimize memory usage --- shared/bin.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'shared') diff --git a/shared/bin.h b/shared/bin.h index 48485c8..1eaa2a7 100644 --- a/shared/bin.h +++ b/shared/bin.h @@ -13,6 +13,13 @@ extern uint8_t g_w2_endianness; +#define W2_CAST_BIN(type, in, out) type *out = (type*) &in->data; +#define W2_CREATE_MSG_BIN(type, normal, bin) \ + W2_CREATE_MSG_SIZE_BIN(type, sizeof(type), normal, bin) +#define W2_CREATE_MSG_SIZE_BIN(type, size, normal, bin) \ + w2_s_bin* bin = malloc(size); \ + type* normal = (type*) &bin->data; + typedef struct { uint16_t bytes; uint8_t data[]; -- cgit v1.2.3