Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!MIMSY.UMD.EDU!chris From: chris@MIMSY.UMD.EDU (Chris Torek) Newsgroups: comp.sys.pyramid Subject: Re: Pyramid's "non-standard" C compiler Message-ID: <8908011641.AA03814@mimsy.umd.edu> Date: 1 Aug 89 16:41:55 GMT Sender: daemon@ucbvax.BERKELEY.EDU Organization: The Internet Lines: 47 >In article <235@massey.ac.nz> K.Spagnolo@massey.ac.nz (Ken Spagnolo) writes: >>I refer to the fact that in Pyramid C, given 'struct x x;', a call to >>function y() like 'y(x);' will pass to y() the entire structure x, rather >>that just a pointer to x, as is the case with all other C compilers I know >>about. Then all those other compilers are broken. This practise went out of style with Version 7 Unix. The Berkeley and System V VAX C compilers pass structures by value (as all C compilers must) by copying the entire structure onto the stack before the function call, and popping it off afterward. In article <13095@polyslo.CalPoly.EDU> polyslo!hoyt@decwrl.dec.com (Sir Hoyt) writes: >Um, if memory servers me right, there is nothing in the >C language the specifies how structures are to be passed. It must be by value. The exact mechanics of call-by-value are not defined by C, as they tend to be machine dependent. >What do we do? We bitch about the rotten code people write. >Not all of the world is a Vax..... ( as the saying goes ) In my experience, the only code that ever failed on a Pyramid but happened to work on a VAX was something from Imagen, which had some code like the following: struct one_word_long { int field; }; f() { struct one_word_long foo; ... g(foo); } g(x) int x; { ... } which is just plain wrong. In this case, the simplest fix was to change the caller (f()) to pass `foo.field' instead of `foo'. The reason it failed on the Pyramid but worked on VAXen and Suns is that the Pyramid has two stacks (control and data) and on the Pyramid, all structure values were passed on the data stack, regardless of structure size, while simple values (int, float, etc) were passed in registers. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris