Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watnot!watmath!clyde!rutgers!husc6!sri-unix!hplabs!pyramid!voder!kontron!cramer From: cramer@kontron.UUCP Newsgroups: comp.lang.c Subject: Re: Why pass structs? (not struct pointers) Message-ID: <1437@kontron.UUCP> Date: Tue, 3-Mar-87 21:51:19 EST Article-I.D.: kontron.1437 Posted: Tue Mar 3 21:51:19 1987 Date-Received: Fri, 6-Mar-87 05:26:45 EST References: <3346@cisunx.UUCP> Distribution: na Organization: Kontron Electronics, Mt. View, CA Lines: 28 > I have been aware of the post V7 C compilers passing and > returning structs from procedures, and I am curious as to > why. > > Passing structures as a whole seems to violate my impression > of the nature of C. I feel that a good reason for passing > arrays by reference (yes, I know that the pointer is passed by > value :-) is to save an enormous ammount of stack and CPU time. > > To pass a structure by value seems to require an arbitrarily > large amount of stack; but more importantly, non-atomic > stack operations. That is, that I can push a long, int, char > or any pointer with (hopefully) one machine-op. To pass > a structure would require a number of pushes, a block-copy-op, > or some looping copy code. > > I imagine that the people who added this to C had good reason, > so could someone please tell me what I am missing or have > gotten wrong? > > matt wartell One reason I have for occasionally passing a structure, rather than a pointer to the structure, is if the structure is purely an input, and I want to make sure that the called function doesn't alter the caller's copy of the structure. Clayton E. Cramer