Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!think!paperboy!meissner From: meissner@osf.org (Michael Meissner) Newsgroups: comp.lang.c Subject: Re: Structures Message-ID: Date: 1 Mar 90 21:35:41 GMT References: <14302@reed.UUCP> Sender: news@OSF.ORG Organization: Open Software Foundation Lines: 41 In-reply-to: minar@reed.bitnet's message of 28 Feb 90 20:13:15 GMT In article <14302@reed.UUCP> minar@reed.bitnet (Nelson Minar,(???)) writes: | My copy of K&R 1 (I'll be getting 2 soon..) says | | "There are only two things that can be done with a structure or a union: | name one of its members (by means of the . operator); or take its address | (by unary &). Other operations, such as assigning from or to it or passing | it as a parameter, draw an error message. In the future, it is expected | that these operations, but not necessarily others, will be allowed." | | 1] What does ansi say about this? ANSI requires that implementations be able to pass structures by value, return them, and assigning structures. Note that the maximum size of a structure that you can pass is implementation defined. For example, unless they've changed the calling sequence recently, on a VAX, the size of all of the arguments must be less than 512 longwords (or bytes, I don't use vaxen). | 2] It seems that passing a structure-by-value is illegal under this rule. | Why this limitation in the original C? Possibly because the PDP11 did not have a block move instruction, or possibly Dennis Ritchie hadn't gotten around to it when K&R-I was written. The changes mentioned in #1, were made after K&R-I, but before V7 was shipped outside of Bell Labs. The same change added enum's. | 3] My C compiler (Turbo C 2.0) doesn't mind passing a structure-by-value, | and it allows you to set two structures equal to each other, automatically | copying the elements. Is this standard behavior for most C compilers? Why | does Turbo C have an warning "Warning: structure passed by value" | if it is legal TC 2.0 code? Because it is potentially non-portable? The warning message is probably because the usage is not allowed by K&R (though most compilers do support it). -- Michael Meissner email: meissner@osf.org phone: 617-621-8861 Open Software Foundation, 11 Cambridge Center, Cambridge, MA Catproof is an oxymoron, Childproof is nearly so