Path: utzoo!mnetor!uunet!husc6!bloom-beacon!gatech!hao!ames!ptsfa!ihnp4!chinet!dag From: dag@chinet.UUCP (Daniel A. Glasser) Newsgroups: comp.lang.c Subject: Re: A bad design decision early on in ANSI C. Message-ID: <2061@chinet.UUCP> Date: 4 Jan 88 21:17:34 GMT References: <1322@sugar.UUCP> <1942@ho95e.ATT.COM> <2313@cxsea.UUCP> Reply-To: dag@chinet.UUCP (Daniel A. Glasser) Organization: Chinet - Public Access Unix Lines: 43 In article <2313@cxsea.UUCP> blm@cxsea.UUCP (Brian Matthews) writes: [ stuff about structure assignment and data hiding deleted ] >This can happen whether or not structure assignment is available. You just >have to pass pointers (perhaps to a copy) instead of the item itself, expect >pointers to be returned (or pass a pointer to an item to be filled in), and use >memcpy or bcopy to make copies of the item. Structure assignment adds to the >"cleanness" of the language (you can pass and assign any scalar data type), >makes copying structures slightly more efficient timewise (inline copy instead >of function call. Of course this will increase the size the code), but doesn't >add any data hiding capabilities that weren't already there. > >-- >Brian L. Matthews "A power tool is not a toy. >...{mnetor,uw-beaver!ssc-vax}!cxsea!blm Unix is a power tool." >+1 206 251 6811 >Computer X Inc. - a division of Motorola New Enterprises Actually, using pointers instead of structure assignment/passing in information hiding is not a solution, since after the assignment the original copy might be changed by another routine and/or the hidden type might be a member of a structure that is written to a file and then read. If a pointer is used, the referenced data must be written to the file, some file pointer (potentially non-compatible in size to a memory pointer (ie. PDP-11) stored in somehow and then the two must be read back into memory and the pointer must be adjusted. This, though possible, is not something that the beginning programmer will want to be faced with or the experienced programmer burdened with. I agree that structure assignment/passing is here to stay. Although compilers on the market at this time do not support this, most do. This does put a burden on the compiler vendor, but not on the user of the compiler. The "missing &" problem is a common programming error, but so is expecting sizeof(char *) == int, and both produce lots of problems for those who are not expecting them. The ANSI function prototyping catches most of these problems, and compilers that don't support prototyping need not support structure passing, since they aren't ANSI conforming anyway. -- Daniel A. Glasser ...!ihnp4!chinet!dag ...!ihnp4!mwc!dag ...!ihnp4!mwc!gorgon!dag One of those things that goes "BUMP!!! (ouch!)" in the night.