PACK() macro

This commit is contained in:
2022-08-14 13:23:39 +06:00
parent 4e162bd474
commit 7ba7201d3a
13 changed files with 51 additions and 25 deletions

View File

@@ -11,7 +11,6 @@ extern "C" {
#include <locale.h>
#include <time.h>
#include <setjmp.h>
#include <unistd.h>
#define dbg(N) printf("\e[95m%d\n",N)
@@ -36,6 +35,7 @@ extern "C" {
#pragma GCC error "unknown compiler"
#endif
#ifdef _MSC_VER
#define IFWIN(YES, NO) YES
#define IFMSC(YES, NO) YES
@@ -53,6 +53,15 @@ extern "C" {
#define NULL ((void*)0)
#endif
#ifdef __GNUC__
#define PACK(...) __VA_ARGS__ __attribute__((__packed__))
#elif defined(_MSC_VER)
#define PACK(...) __pragma(pack(push, 1)) __VA_ARGS__ __pragma(pack(pop))
#endif
#if __cplusplus
}
#endif

View File

@@ -16,7 +16,7 @@ typedef int64_t int64;
typedef uint64_t uint64;
typedef float float32;
typedef double float64;
typedef enum __attribute__((__packed__)) my_type {
typedef enum my_type PACK({
Null, Float32, Float64, Char, Bool,
UInt8, Int8, UInt16, Int16, UInt32, Int32, UInt64, Int64,
UInt8Ptr, Int8Ptr, UInt16Ptr, Int16Ptr, UInt32Ptr, Int32Ptr, UInt64Ptr, Int64Ptr,
@@ -25,7 +25,7 @@ typedef enum __attribute__((__packed__)) my_type {
AutoarrInt8Ptr, AutoarrUInt8Ptr, AutoarrInt16Ptr, AutoarrUInt16Ptr,
AutoarrInt32Ptr, AutoarrUInt32Ptr, AutoarrInt64Ptr, AutoarrUInt64Ptr,
AutoarrUnitypePtr, AutoarrKVPairPtr, knSocketPtr
} my_type;
}) my_type;
#define my_type_last knSocketPtr
const char* my_type_name(my_type t);