Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watnot!watmath!clyde!rutgers!ll-xn!mit-eddie!husc6!panda!genrad!decvax!decwrl!sun!gorodish!guy From: guy@gorodish.UUCP Newsgroups: comp.lang.c Subject: Re: Why pass structs? (not struct pointers) Message-ID: <14250@sun.uucp> Date: Fri, 27-Feb-87 14:44:56 EST Article-I.D.: sun.14250 Posted: Fri Feb 27 14:44:56 1987 Date-Received: Sun, 1-Mar-87 10:40:24 EST References: <3346@cisunx.UUCP> Sender: news@sun.uucp Reply-To: guy@sun.UUCP (Guy Harris) Distribution: na Organization: Sun Microsystems, Mountain View Lines: 32 >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. Yes, but the mere fact that something takes a lot of CPU time or stack space isn't sufficient to indicate that C shouldn't do it; some people, for instance, might argue that C implementations on the VAX shouldn't use "calls", because they take a lot of 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. Well, you can't. For instance, on the machine on which C was originally implemented, you *can't* push a long with one machine instruction. Again, "can I do this in a machine instruction" is the wrong question, as is "is this operation atomic". (Remember, the instruction to push such an item may not be atomic, even if it is done in one machine instruction; what if it takes a page fault when doing the push, or gets a segmentation violation because the stack hasn't grown far enough yet?) >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? According to Dennis Ritchie (at least as far as I remember his answer to this question), the reason why structure assignment, structure-valued arguments, and structure-valued functions were added was to make C treat all scalar objects in a similar fashion.