Article View: comp.std.c
Article #2426Re: Representation Clauses
From: Steven Preston
Date: Fri, 15 Feb 1991 14:50
Date: Fri, 15 Feb 1991 14:50
30 lines
1624 bytes
1624 bytes
>>>>> In article <4125@skye.ed.ac.uk>, richard@aiai.ed.ac.uk (Richard Tobin) writes:
> In article <91042.160311KKEYTE@ESOC.BITNET> KKEYTE@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
Technical Details
Message-ID:
<9102150950.AA14987@LL.MIT.EDU>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!clyde.concordia.ca!nstn.ns.ca!news.cs.indiana.edu!samsung!uakari.primate.wisc.edu!sdd.hp.com!ucsd!ucbvax!LL.MIT.EDU!prestonShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!clyde.concordia.ca!nstn.ns.ca!news.cs.indiana.edu!samsung!uakari.primate.wisc.edu!sdd.hp.com!ucsd!ucbvax!LL.MIT.EDU!preston From: preston@LL.MIT.EDU (Steven Preston) Newsgroups: comp.std.c Subject: Re: Representation Clauses Message-ID: <9102150950.AA14987@LL.MIT.EDU> Date: 15 Feb 91 14:50:13 GMT Sender: daemon@ucbvax.BERKELEY.EDU Lines: 30