Skip to contentSkip to conversation

one pragma pack vs. many, many __attribute__((packed))

DISCUSSION Steve French 1 participant 1 message Oct 27, 2005

lore
Share & tools
lore
#0 lore raw

Seems like a big annoyance, but gcc on some platforms (arm) will generate different code for
pragma pack(1)
vis the corresponding more verbose alternative ie specifying

	__attribute__((packed)) 

on each structure one by one. Presumably there are good reasons for why packing them across the whole file does not mean you can necessarily read them when they aren't aligned (my imagination is not that good)

Although it makes the code more verbose to individually call out packing on each structure, I don't see any reasonable alternative that would work (at least on arm) as I have to deal with structures coming in off the network that are packed - and in some cases not aligned on 2 or 4
byte boundaries either. special case parsing them off the wire (as
opposed to accessing them with their structure field names) would be worse, and copying them into a temp buffer would be worse ... are there no reasonable magic compile options or pragmas that will have the effect of attribute__((packed)) without being so verbose?