Newsgroups: comp.lang.c Path: utzoo!henry From: henry@utzoo.uucp (Henry Spencer) Subject: Re: Structures Message-ID: <1990Mar2.171407.1194@utzoo.uucp> Organization: U of Toronto Zoology References: <14302@reed.UUCP> Date: Fri, 2 Mar 90 17:14:07 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... K&R1 was obsolete a decade ago, in this and some other minor respects. >1] What does ansi say about this? Structures can be assigned, passed, and returned, plus (with some limits) initialized. >2] It seems that passing a structure-by-value is illegal under this rule. >Why this limitation in the original C? Basically because C came out of the BCPL heritage, in which there was really only one data type (the word) and all values were one word wide. C departed from this pretty early for floating point, but bigger departures were slow in coming. Passing pointers to structs is usually more efficient and met most early needs just as well. >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? It's standard behavior for modern compilers; the warning is probably because it's not K&R1 conformant. -- MSDOS, abbrev: Maybe SomeDay | Henry Spencer at U of Toronto Zoology an Operating System. | uunet!attcan!utzoo!henry henry@zoo.toronto.edu