p500vax:pat (04/05/83)
Our 4.1 VAX compiler assigns bit fields from right to left, ie. from low order to high, while the 68000 compiler from MIT assigns bit fields from left to right, ie. from high order to low. So, to set bit 15 on the VAX struct{ unsigned short unused:15, bit:1; }foo; foo.bit = 1; to set bit 15 on the 68000 struct{ unsigned short bit:1; }foo; foo.bit = 1; The C reference manual says "Fields are assigned to words ... right-to-left on the PDP-11 and left-to-right on other machines" so the VAX compiler is "wrong". Of course the manual also says that it "describes the C language on the DEC PDP-11, the Honeywell 6000, the IBM System/370, and the Interdata 8/32", so maybe this is what they mean by other. If I were writing a C compiler I would put a high value on maintaining compatability with PDP-11s, so I'd say that MIT took the standard a bit too literally.
crc (04/06/83)
One would expect compiliers to assign bit fields the same way the cpu manufaturer does. In this case MIT is wrong as the 68000 counts bits from LSB to MSB, like the pdp11. Unfortunately the 68000 counts bytes the other way around, ie from MSByte to LSByte. It would be cleaner if they counted bits and bytes the same way. Well at least you can *REALLY* directly address more than 64k unlike the 8086, z8000 and 9900.
guy (04/09/83)
Well, it's probably actually a function of how you number your bytes. On
the PDP-11, the low-order byte of a word has the even address and the
high-order byte has the next odd address, i.e.:
+--------+--------+
| n + 1 | n |
+--------+--------+
For hysterical raisins (namely, the way the FP-11 handles 32-bit integers),
the high- and low-order *words* of a *longword* are not handled this way
on PDP-11 C, although they ARE handled that way on all of DEC's PDP-11
software. The VAX-11 handles bytes this way (and handles words in a longword
this way, i.e. differently from PDP-11 C). The bits of a byte/word/longword/
quadword are also numbered this way. As such, they probably decided to
assign bit-fields from the low-order bit to the high-order bit.
The 68000 handles bytes and words differently (although, for no conceivable
reason, it still numbers bits from the low-order bit up), so they probably
decided to do bit fields from the high-order bit to the low-order bit.
Since you can't transmit raw binary data from the PDP-11 or the VAX-11 to
the 68000 because of the byte-order problem, it's not clear that doing the
bit fields in the PDP-11/VAX-11 fashion would really help.
The moral of the story is: if you want to exchange data between systems, put
it either in ASCII or in a binary form which is insensitive to bit order.
The "tar" tape format, the new "cpio" tape format, and the Berkeley archive
format do the former, while the System V archive format and the USG UNIX
"pack" Huffman-coded file format do the latter.
Guy Harris
RLG Corporation
{seismo,mcnc,we13}!rlgvax!guy