so how do I do it? (was Re: call to revolt)
Chris Torek
torek at elf.ee.lbl.gov
Thu Jun 27 23:49:17 AEST 1991
In article <1991Jun27.115736.18417 at tkou02.enet.dec.com>
diamond at jit533.enet@tkou02.enet.dec.com (Norman Diamond) writes:
>Huh? Oh, you mean that the buffer was laid out by some other entity
>than your C program. Yes, C (along with every other language except Ada!)
>fails to provide for manipulations of such data.
Not strictly true: Mesa (for instance) allows record specifiers that
include actual bit or byte addresses. In Mesa, though, it was all
or nothing: either you said
type foo = record [ blah, blah, blah ];
and got arbitrary compiler-munching (including order), or you gave it
the `machine-dependent' clause and got absolute control.
There are a bunch of different concepts that different languages do
or do not allow you to express. One is:
This is exactly how the bits work. Change none of them.
[Example: Mesa `machine-dependent' records]
which is good for talking to devices or network byte streams. Another
is:
This is the data I need carried about. Optimize for time.
[Example: Pascal records]
Still another is:
This is the data I need carried about. Optimize for space.
[Example: Pascal packed records]
C takes a somewhat wishy-washy approach and tries to do everything at
once: `struct's are not reorderable, but are not necessarily packed.
As it turns out, though, even Pascal's packed/notpacked approach is
insufficient in some cases: you might want to say `pack this as much as
is convenient, but not so much as to cause order of magnitude
slowdowns'. Some Pascal compilers treat
type seven = 0..127;
var foo : packed array [0..16777215] of sevenbits;
as arrays of bytes, some as arrays of seven-bit fields; the latter
is sometimes severely slower, but does save 2 megabytes.
--
In-Real-Life: Chris Torek, Lawrence Berkeley Lab CSE/EE (+1 415 486 5427)
Berkeley, CA Domain: torek at ee.lbl.gov
More information about the Comp.std.c
mailing list