Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!yetti!geac!daveb From: daveb@geac.UUCP (Dave Collier-Brown) Newsgroups: comp.lang.c Subject: Re: Re: Arrays of Unknown Length in Structures (and sizeof) Message-ID: <1609@geac.UUCP> Date: Wed, 14-Oct-87 10:23:02 EDT Article-I.D.: geac.1609 Posted: Wed Oct 14 10:23:02 1987 Date-Received: Thu, 15-Oct-87 19:47:09 EDT References: <243@mit-prep.ARPA> <1044@ius1.cs.cmu.edu> <668@its63b.ed.ac.uk> <3453@diku.UUCP> Reply-To: daveb@geac.UUCP (Dave Collier-Brown) Organization: The little blue rock next to that twinkly star. Lines: 44 Keywords: structs x.400 unix Summary: examples, with context A bit of side-discussion on the question: here's some examples from real things which use both variable and fixed-size structs, and why. Fixed: This one's easy. Unix wants to have the compiler generate efficient code for stepping through small, possibly ordered, tables of data. Therefore it defines p++ as "increment p by sizeof the things p points to, and the code generated looks like: add regP,size compare regX,offset+regP ... when searching a table of elements of size "size" for something at offset "offset" in each element. For example, disk-cache buffer headers. variable: Not so easy. The best example I've seen was declarations for describing x.400-like hierarchical message structures... +--------------------------------------------------------------------+ || tag || length || subtag | length | data | subtag | length | data || +--------------------------------------------------------------------+ +------------------------+------------------------+ an embedded record another one +--------------------------------------------------------------------+ the containing record. Most of the other examples of variable-sized structs were attempts to save a pointer-indirection instruction. Since indirections are usually cheap (even under GCOS), avoidance of them is *not* a win if the price is hard-to-maintain variable-size struct-munging code. And on many machines (Vax, HW-BULL, Motorola), the cost of an indirection in space and time works out to less than the extra calculations for doing anything more than allocating and discarding the variable-size structs. --dave (compilers are smawt, hawold) c-b -- David Collier-Brown. {mnetor|yetti|utgpu}!geac!daveb Geac Computers International Inc., | Computer Science loses its 350 Steelcase Road,Markham, Ontario, | memory (if not its mind) CANADA, L3R 1B3 (416) 475-0525 x3279 | every 6 months.