Adds better packing defines.
This commit is contained in:
parent
02bc1933ab
commit
2328ce6408
2 changed files with 13 additions and 14 deletions
14
libvm/exp.h
14
libvm/exp.h
|
@ -1,9 +1,9 @@
|
|||
#pragma once
|
||||
|
||||
#if defined(__gcc)
|
||||
#define PACKED __attribute__ ((packed))
|
||||
#if defined(_MSC_VER)
|
||||
#define EXP_PACKED_STRUCT
|
||||
#else
|
||||
#define PACKED
|
||||
#define EXP_PACKED_STRUCT __attribute__ ((packed))
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
@ -19,7 +19,7 @@ struct expfile
|
|||
uint32_t numSections; // Number of sections
|
||||
uint32_t posMeta; // File pointer of first metadata entry
|
||||
uint32_t posSections; // File pointer of first section definition;
|
||||
} PACKED;
|
||||
} EXP_PACKED_STRUCT;
|
||||
|
||||
struct expsection
|
||||
{
|
||||
|
@ -28,13 +28,13 @@ struct expsection
|
|||
uint32_t start; // File pointer to the begin of the section
|
||||
uint32_t length; // Length of the section in bytes
|
||||
char name[64]; // Name of the section, null terminated c-string
|
||||
} PACKED;
|
||||
} EXP_PACKED_STRUCT;
|
||||
|
||||
struct expstring
|
||||
{
|
||||
uint32_t start; // File pointer to the start of the string
|
||||
uint32_t length; // Length of the string in bytes.
|
||||
} PACKED;
|
||||
} EXP_PACKED_STRUCT;
|
||||
|
||||
struct expmeta
|
||||
{
|
||||
|
@ -45,7 +45,7 @@ struct expmeta
|
|||
int32_t i; // int32_t
|
||||
struct expstring s; // ExpString
|
||||
} value; // Value of the metadata
|
||||
} PACKED;
|
||||
} EXP_PACKED_STRUCT;
|
||||
|
||||
typedef struct expfile expfile_t;
|
||||
typedef struct expsection expsection_t;
|
||||
|
|
13
libvm/vm.h
13
libvm/vm.h
|
@ -3,13 +3,12 @@
|
|||
#include <stddef.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#if defined(__gcc)
|
||||
#define PACKED __attribute__ ((packed))
|
||||
#if defined(_MSC_VER)
|
||||
#define VM_PACKED_STRUCT
|
||||
#else
|
||||
#define PACKED
|
||||
#define VM_PACKED_STRUCT __attribute__ ((packed))
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#else
|
||||
|
@ -86,10 +85,10 @@ struct instruction
|
|||
unsigned int flags : 1;
|
||||
unsigned int output : 2;
|
||||
uint32_t argument;
|
||||
} PACKED ;
|
||||
} VM_PACKED_STRUCT ;
|
||||
|
||||
static_assert(sizeof(Instruction) == 8, "Instruction must be 8 bytes large.");
|
||||
static_assert(offsetof(Instruction, argument) == 4, "Argument must be must be 8 bytes large.");
|
||||
static_assert(sizeof(struct instruction) == 8, "Instruction must be 8 bytes large.");
|
||||
static_assert(offsetof(struct instruction, argument) == 4, "Argument must be must be 8 bytes large.");
|
||||
|
||||
struct spu
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue