[comp.sys.pyramid] Pyramid's "non-standard" C compiler

KSpagnol@massey.ac.nz (Ken Spagnolo) (08/01/89)

Don't get me wrong.  I quite like our Pyramid 9815.  There is, however,
one thing that has caused numerous problems for people porting software
around here.  I apologize if this has been discussed before.  In fact,
I'd be quite surprised to hear it hadn't.

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.  This causes a fair amount of havoc when trying to bring up pd
software that hasn't been 'Pyramidized'.  We have gone thru several painful
experiences with things like atalkad where we had to use lint, or some
less scientific method, to figure out where to change occurences of y(x)
to y(&x), etc.

What do other Pyramid users do about this?  Has anyone come up with an
easy method of discovering where changes need to be made, or written a
program to do so?  Would it not be a simple matter to have a cc option
that turned off this feature?  Might there be an undocumented one already?
All responses are appreciated!

==============================================================================
Ken Spagnolo - Systems Programmer, Postmaster, Usenet Administrator, etc...
    Computer Centre, Massey University, Palmerston North, New Zealand
K.Spagnolo@massey.ac.nz     Phone: +64-63-69099 x8587     New Zealand = GMT+12
==============================================================================

hoyt@polyslo.CalPoly.EDU (Sir Hoyt) (08/01/89)

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.  

	Um, if memory servers me right, there is nothing in the
	C language the specifies how structures are to be passed.
	It only states that you can pass them.  Pyramid is not the only
	machine that does this, the IBM RT will also pass the entire
	struct at times.


>This causes a fair amount of havoc when trying to bring up pd
>software that hasn't been 'Pyramidized'.  We have gone thru several painful
>experiences with things like atalkad where we had to use lint, or some
>less scientific method, to figure out where to change occurences of y(x)
>to y(&x), etc.

	Any code that breaks because of this is wrong.  I have moved
	code between Pyramids, Suns, and Sequents with out any
	problems what so ever.  From what you say, it seems to me
	that the people think:

		int y( x )
		struct yy *x;
		{

		}

	Should be called like:

		struct yy c;
		.
		.
		y( c );
		.
		.

	This is wrong, period.  the function 'y' should be declared
	like:

		struct y( x )
		struct yy x;
		{

		}


>What do other Pyramid users do about this?  Has anyone come up with an
>easy method of discovering where changes need to be made, or written a
>program to do so?  Would it not be a simple matter to have a cc option
>that turned off this feature?  Might there be an undocumented one already?
>All responses are appreciated!

	What do we do? We bitch about the rotten code people write.
	Not all of the world is a Vax..... ( as the saying goes )


-- 
John H. Pochmara				 A career is great, 
UUCP: {csun,voder,trwind}!polyslo!hoyt		 But you can't run your 
Internet: hoyt@polyslo.CalPoly.EDU		 fingers through its hair
							-Graffiti 4/13/83

csg@pyramid.pyramid.com (Carl S. Gutekunst) (08/01/89)

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....

Nope. Go to the back of the class. If you want to pass a pointer to a struct,
you have to take its address with the '&' operator. That *is* standard C. (See
K&R section 6.2, and the C Reference Manual section 7.1.) "Old" K&R implemen-
tations will flag an error if you pass the structure directly; these days that
means my PDP-11, my Cromemco Z80, and not much else. All modern C compilers
copy and pass the structure.

<csg>

chris@MIMSY.UMD.EDU (Chris Torek) (08/01/89)

>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