Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Struct padding
#1
Hi! I have a question.
Are structs automatically padded during compilation? I recommend you to order your fields by size or manually padding your fields like this :

Field ordering :
Code:
typedef struct
{

typedef struct
{
int x; /*!< horizontal position */
int y; /*!< vertical position */
int width; /*!< horizontal size */
int height; /*!< vertical size */
uint16_t id; /*!< unique ID */
uint16_t gid; /*!< graphic ID (tile index) */
uint16_t flags; /*!< attributes (FLAG_FLIPX, FLAG_FLIPY, FLAG_PRIORITY) */
uint8_t type; /*!< type property */
bool visible; /*!< visible property */
char name[64]; /*!< name property */
}
TLN_ObjectInfo;

Manual padding :
Code:
typedef struct
{
uint16_t id; /*!< unique ID */
uint16_t gid; /*!< graphic ID (tile index) */
uint16_t flags; /*!< attributes (FLAG_FLIPX, FLAG_FLIPY, FLAG_PRIORITY) */
uint16_t padding;
int x; /*!< horizontal position */
int y; /*!< vertical position */
int width; /*!< horizontal size */
int height; /*!< vertical size */
uint8_t type; /*!< type property */
bool visible; /*!< visible property */
char name[64]; /*!< name property */
}
TLN_ObjectInfo;
Reply


Messages In This Thread
Struct padding - by System64 - 02-06-2025, 02:55 AM
RE: Struct padding - by megamarc - 02-07-2025, 03:27 AM
RE: Struct padding - by System64 - 02-07-2025, 08:23 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)