Hi,
I need to know how I can create a packed structure in GCC, ie. it only has as many bytes as needed.
thanks.
Packed Strcutures in GCC
Re:Packed Strcutures in GCC
typedef struct {
/* Code here */
} __attribute__((packed));
/* Code here */
} __attribute__((packed));
Re:Packed Strcutures in GCC
make sure you're not using this packed structure to read in data from a file.. cause it's very iffy. you're better off just reading in each byte to make sure you have the correct endian.
- Nick
- Nick
Re:Packed Strcutures in GCC
With this would I put the name of the structure before __attribute__ ((packed)) like below?
typedef struct {
/* Code here */
} struct_name __attribute__((packed));
thanks.
typedef struct {
/* Code here */
} struct_name __attribute__((packed));
thanks.
Re:Packed Strcutures in GCC
I dont think it really matters, i put my struct names after the __attribute__((packed))
Re:Packed Strcutures in GCC
Also, this seems to work on both gcc and the Microsoft compiler:
Code: Select all
#pragma pack(push, 1) /* use 1, 2, 4, etc. */
struct your_structure
{
};
#pragma pack(pop)