2525# define O_BINARY 0
2626#endif
2727
28- #pragma pack(1)
28+ #ifdef __WATCOMC__
29+ #define PACKEDPREFIX _Packed
30+ #elif defined(_MSC_VER)
31+ #define PACKEDPREFIX __pragma (pack(push,1 ))
32+ #else
33+ #define PACKEDPREFIX
34+ #endif
35+
36+ #ifdef __GNUC__
37+ #if defined(_WIN32) && !defined(__clang__)
38+ #define PACKEDSUFFIX __attribute__ ((packed,gcc_struct))
39+ #else
40+ #define PACKEDSUFFIX __attribute__ ((packed))
41+ #endif
42+ #elif defined(_MSC_VER)
43+ #define PACKEDSUFFIX __pragma (pack(pop))
44+ #else
45+ #define PACKEDSUFFIX
46+ #endif
47+
48+ #define PACKED_STRUCT (...) PACKEDPREFIX struct __VA_ARGS__ PACKEDSUFFIX
2949
3050#if defined(_arch_dreamcast)
3151#define YESBUTTONNAME " A"
@@ -741,14 +761,14 @@ extern statetype states[numstates]; // [FG] statetype states[] array
741761//
742762// ---------------------
743763
744- typedef struct statstruct
764+ typedef PACKED_STRUCT ( statstruct
745765{
746766 byte tilex,tiley;
747767 short shapenum; // if shapenum == -1 the obj has been removed
748768 byte *visspot;
749769 uint32_t flags;
750770 byte itemnumber;
751- } statobj_t ;
771+ }) statobj_t;
752772
753773
754774// ---------------------
@@ -762,14 +782,14 @@ typedef enum
762782 dr_open,dr_closed,dr_opening,dr_closing
763783} doortype;
764784
765- typedef struct doorstruct
785+ typedef PACKED_STRUCT ( doorstruct
766786{
767787 byte tilex,tiley;
768788 boolean vertical;
769789 byte lock;
770790 doortype action;
771791 short ticcount;
772- } doorobj_t ;
792+ }) doorobj_t;
773793
774794
775795// --------------------
@@ -778,7 +798,7 @@ typedef struct doorstruct
778798//
779799// --------------------
780800
781- typedef struct objstruct
801+ typedef PACKED_STRUCT ( objstruct
782802{
783803 activetype active;
784804 short ticcount;
@@ -804,7 +824,7 @@ typedef struct objstruct
804824
805825 short temp1,temp2,hidden;
806826 struct objstruct *next,*prev;
807- } objtype;
827+ }) objtype;
808828
809829enum
810830{
855875//
856876// ---------------
857877
858- typedef struct
878+ typedef PACKED_STRUCT (
859879{
860880 short difficulty;
861881 short mapon;
@@ -874,7 +894,7 @@ typedef struct
874894 int32_t TimeCount;
875895 int32_t killx,killy;
876896 boolean victoryflag; // set during victory animations
877- } gametype;
897+ }) gametype;
878898
879899
880900typedef enum
0 commit comments