Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!think!harvard!seismo!brl-adm!brl-smoke!smoke!dan@BBN-PROPHET.ARPA From: dan@BBN-PROPHET.ARPA (Dan Franklin) Newsgroups: net.lang.c Subject: Re: Address of array Message-ID: <2051@brl-smoke.ARPA> Date: Mon, 24-Mar-86 13:52:11 EST Article-I.D.: brl-smok.2051 Posted: Mon Mar 24 13:52:11 1986 Date-Received: Wed, 26-Mar-86 04:47:31 EST Sender: news@brl-smoke.ARPA Lines: 37 Bennett E. Todd III (mcnc!ecsvax!duccpc!bet) suggests that structure copying is a bad idea and wants structures to behave like arrays, instead of the reverse as everone else is suggesting. I couldn't disagree more. Having the compiler "automagically" copy structures around for me is perhaps the single most useful capability recently added to C. It vastly simplifies the problems of dealing with data structures. Rob Pike's paper on the organization of the Blit software (in Software Practice and Experience) demonstrates how clean C programming can be given structures that can be passed as arguments and returned. If structures were only referenced by their addresses, using them would be much more painful (as it used to be), since every time you returned one of the damn things you would have to worry about where the storage was coming from. Here's an example adapted from things in Pike's paper: typedef struct { int x, y; } point_t; point_t mk_point(int, int); rectangle_t output; output = mk_rect(mk_point(x,y), mk_point(x + 5, y + 6)) That is, make a rectangle from two points specifying the corners. Try to imagine doing this simple operation in a world in which structures are not copied. The mk_point routine would either have to take a pointer to an empty structure to be filled in as one of its arguments, either returning that same pointer as its return value (so it could be used in cascaded function calls) or return a pointer to an allocated structure that would have to be freed later (so I'd have to capture it as it went flying by in the middle of this expression), or return a pointer to a static structure that was overwritten with each call (which would make this expression impossible, since the same pointer would be returned in both cases). No matter how you slice it, it would be a lot more than two lines of code, and not nearly as clear. Dan Franklin