Representation Clauses

Steven Preston preston at LL.MIT.EDU
Sat Feb 16 01:50:13 AEST 1991


>>>>> In article <4125 at skye.ed.ac.uk>, richard at aiai.ed.ac.uk (Richard Tobin) writes:

> In article <91042.160311KKEYTE at ESOC.BITNET> KKEYTE at ESOC.BITNET (Karl Keyte) writes:
  [ stuff deleted }
> You can solve this for most machines by doing something like this:

> struct {
>     union {int   a; char x[4];} a;
>     union {char  b; char x[4];} b;
>     union {float c; char x[4];} c;
> } s;

> Of course, if sizeof(int) is greater than 4 you're going to lose.  And
> you have to say s.a.a instead of s.a.

The original poster wanted to force certain alignments on struct
elements to "provide truly portable messages on machines with
different structure alignments." 

But, there is also the problem of big-endian vs. little-endian
machines, and the issue of word size.  The different representations
for floating point is another problem.

There is no convenient, portable way to specify a struct such that the
bit pattern of struct instances can be transmitted between machines.
At best you may be able to write some sort of architecture-independent
``form'' that each machine could convert to its own version of the
struct (like using printf, and scanf).
--
Steve Preston



More information about the Comp.std.c mailing list