Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

__attribute__((packed)) -- what is that?

Status
Not open for further replies.

DanWiFi

Programmer
Jul 7, 2004
7
US
ok I have a structure:


struct dhcp_ippacket_t {
struct dhcp_ethhdr_t ethh;
struct dhcp_iphdr_t iph;
uint8_t payload[DHCP_IP_PLEN];
} __attribute__((packed));

this struct is fed to a call to recv as the buffer to fill (or rather a pointer to it is).

What I don't get is what does this last part mean? the __attribute__((packed));

and I assuming by passing the pointer to this structure to recv as the buffer, then the payload array is the "buffer" part getting filled.

If anyone can point me correctly, it would be greatly appreciated!

Thanks!
DanWiFi
 
> __attribute__((packed))
This is gcc's equivalent of Microsofts #pragma pack(1)

C allows structures to contain internal padding designed to make access to each member of the structure as efficient as possible.

However, sometimes the structure is externally defined and it becomes necessary to squeeze out all that padding. This is what packing in general is designed to achieve.

--
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top