Does #pragma pack(n) apply to all the structures in a source code or it has to be applied to each structure separately ? It's not clear from the manual. In one place it says: "You can use #pragma pack(n) to make sure that any structures with unaligned data are packed." In other: "This pragma aligns members of a structure to the minimum of n"
It doesn't!
When used internally - within a program - there is no data alignment problem: the compiler will consistently use the same alignment rules, so there is no problem!
The problem is that you are trying to use this structure to represent the format of data sent externally to the program - on the communication medium. So the solution to this is simple: don't do that!
It's been mentioned before: the process of taking the information out of the program's internal representation (with its specific padding, alignment, byte-order, data representation, etc) and turning it into the required external format for transmission on the communication medium is known as Serialisation
en.wikipedia.org/.../Serialization
Hans-Bernhard Broeker said,
"serialization is not a valid rationale for packing structures"
The reverse process - receiving data from the communication medium and formatting it into the system's own internal representation - is, naturally enough, referred to a Deserialisation
"It doesn't!"
For external transmission on the communication medium, it also doesn't cover the issues of byte ording, data representation, etc,...
So, one more time:
Hi Andy and Per,
Many thanks for your helps.
I will do some more study on this.