If i have a structure like
struct MixedStructure{
char a;
short b;
int c;
char d;
};
Padding will come to effect.
What I want to know, is if there is a problem sending such a structure over the network.
I mean, this structure actually has 12 bytes (instead of 8) because of padding. If at the other end there is used another padding scheme ( or none), what would be the implications ?
That’s not your only problem. How do you know the sizeof(int) or sizeof(short) is going to be consistent between the two boxs that build that struct?
Most compilers have ways to specify fixed-size variables (ie uint32_t). To answer your specific question, most compilers also have ways to specify packing.
Overlaying a struct onto a buffer of bytes is a very common idiom in high-performance network programming but can be frought with peril. You’ll also need to learn about how this idiom violates strict-aliasing and what endianess is.
I know that in very high-performance situations this is the best option. Just be very very careful and test very well between all the potential hosts that might communicate together. If you don’t need this kind of performance, check out something like google’s protocol buffers for transmitting data in a pretty performant way that lets you avoid knowing about packing/endianess/etc.