R
Richard Harris
Hello,
Consider this:
struct MBD {
double x;
double y;
int i;
}
Now, on my current machine, sizeof(struct MBD) = 24.
I assume this is due to byte alignment on 8 byte boundaries and the
shift of the int i to be 8 bytes, not four.
So... consider the case of socket data transmission, wherein, a client
transmits a struct MBD and it is read by a server.
It would go like this:
read(soc, (char*) address, sizeof(struct MBD));
write(soc, (char*) address, sizeof(struct MBD));
Now, IF the server and client run on the same archiecture, there
should be no problem.
But what if they run on different machines that align bytes differently?
There is now a problem.
One fix would be to find a way to supress byte alignment using a
compiler option
flag (if one exists... does one?)
Another would be to transmit the fields singly.
But these both appear to be kludge workarounds.
Am I thinking about this incorrectly?
Is there a more fundamental or comp.theoretical issue I am overlooking
with regard to the sizeof operator, or structures, or read/write?
thanks
Consider this:
struct MBD {
double x;
double y;
int i;
}
Now, on my current machine, sizeof(struct MBD) = 24.
I assume this is due to byte alignment on 8 byte boundaries and the
shift of the int i to be 8 bytes, not four.
So... consider the case of socket data transmission, wherein, a client
transmits a struct MBD and it is read by a server.
It would go like this:
read(soc, (char*) address, sizeof(struct MBD));
write(soc, (char*) address, sizeof(struct MBD));
Now, IF the server and client run on the same archiecture, there
should be no problem.
But what if they run on different machines that align bytes differently?
There is now a problem.
One fix would be to find a way to supress byte alignment using a
compiler option
flag (if one exists... does one?)
Another would be to transmit the fields singly.
But these both appear to be kludge workarounds.
Am I thinking about this incorrectly?
Is there a more fundamental or comp.theoretical issue I am overlooking
with regard to the sizeof operator, or structures, or read/write?
thanks