Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!thunder.mcrcim.mcgill.edu!snorkelwacker.mit.edu!stanford.edu!agate!dog.ee.lbl.gov!elf.ee.lbl.gov!torek From: torek@elf.ee.lbl.gov (Chris Torek) Newsgroups: comp.std.c Subject: Re: so how do I do it? (was Re: call to revolt) Message-ID: <14739@dog.ee.lbl.gov> Date: 27 Jun 91 13:49:17 GMT References: <1991Jun27.115736.18417@tkou02.enet.dec.com> Reply-To: torek@elf.ee.lbl.gov (Chris Torek) Organization: Lawrence Berkeley Laboratory, Berkeley Lines: 47 X-Local-Date: Thu, 27 Jun 91 06:49:17 PDT In article <1991Jun27.115736.18417@tkou02.enet.dec.com> diamond@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@ee.lbl.gov