YQ2_ALIGNAS_*() in common.h

This commit is contained in:
Daniel Gibson 2019-08-24 20:38:42 -01:00
parent bebd9e73b3
commit f9c77b98af
3 changed files with 17 additions and 16 deletions

View file

@ -374,21 +374,6 @@ SCR_ReadNextFrame(void)
int r;
int command;
// TODO: in case we need this anywhere else, put it in a header!
#if __STDC_VERSION__ >= 201112L // C11 or newer
#define YQ2_ALIGNAS_SIZE(SIZE) _Alignas(SIZE)
#define YQ2_ALIGNAS_TYPE(TYPE) _Alignas(TYPE)
#elif defined(__GNUC__) // GCC and clang should support this attribute
#define YQ2_ALIGNAS_SIZE(SIZE) __attribute__(( __aligned__(SIZE) ))
#define YQ2_ALIGNAS_TYPE(TYPE) __attribute__(( __aligned__(__alignof__(TYPE)) ))
#elif defined(_MSC_VER)
#define YQ2_ALIGNAS_SIZE(SIZE) __declspec( align(SIZE) )
#define YQ2_ALIGNAS_TYPE(TYPE) __declspec( align( __alignof(TYPE) ) )
#else
#warning "Please add a case for your compiler here to align correctly"
#define YQ2_ALIGNAS_TYPE(TYPE)
#endif
// the samples array is used as bytes or shorts, depending on bitrate (cin.s_width)
// so we need to make sure to align it correctly
YQ2_ALIGNAS_TYPE(short) byte samples[22050 / 14 * 4];

View file

@ -53,6 +53,22 @@
#define CFGDIR ".yq2"
#endif
// stuff to align variables/arrays
#if __STDC_VERSION__ >= 201112L // C11 or newer
#define YQ2_ALIGNAS_SIZE(SIZE) _Alignas(SIZE)
#define YQ2_ALIGNAS_TYPE(TYPE) _Alignas(TYPE)
#elif defined(__GNUC__) // GCC and clang should support this attribute
#define YQ2_ALIGNAS_SIZE(SIZE) __attribute__(( __aligned__(SIZE) ))
#define YQ2_ALIGNAS_TYPE(TYPE) __attribute__(( __aligned__(__alignof__(TYPE)) ))
#elif defined(_MSC_VER)
#define YQ2_ALIGNAS_SIZE(SIZE) __declspec( align(SIZE) )
#define YQ2_ALIGNAS_TYPE(TYPE) __declspec( align( __alignof(TYPE) ) )
#else
#warning "Please add a case for your compiler here to align correctly"
#define YQ2_ALIGNAS_TYPE(TYPE)
#endif
/* ================================================================== */
typedef struct sizebuf_s

View file

@ -28,7 +28,7 @@
#include "header/server.h"
byte fatpvs[65536 / 8];
static YQ2_ALIGNAS_TYPE(long) byte fatpvs[65536 / 8];
/*
* Writes a delta update of an entity_state_t list to the message.