[comp.bugs.4bsd] Taking the address of parameters

srg@quick.COM (Spencer Garrett) (09/20/89)

< ....  In C, parameters to (non-prototyped) functions are widened,
< so that `char' and `short' both become `int'.  On a VAX, when one writes
< 
< 	f(x) char x; { char *p = &x; ... }	
< 
< one gets a pun from the actual parameter (which has been `sent in' on
< the stack as an int) to the desired parameter (a char), while on the
< 680x0, one gets a conversion.  ...
< In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)

I would call it a conversion either way, but only big-endian machines
need to muck with the address in the process.  At least it's a
compile-time conversion, and doesn't cost any execution time on
either flavor of machine.

In article <45717@bbn.COM>, news@bbn.COM (News system owner ID) writes:
> I would add one further though to this: avoid expressions like the
> above f(x) like the plague.  This will, regretably, work on Vax,
> 68xxx, etc. "normal processors", but will fail miserably on machines
> like a Pyramid where the first N arguments to a function are placed in
> a register window.  Just go and try to take the address of a register
> :-(.
> 		-- Paul Placeway
> 		   <pplaceway@bbn.com>, <paul@cis.ohio-state.edu>

Ah, but this is perfectly respectable C, and taking the address
of a register WORKS on a Pyramid for this very reason.  The only
additional silliness you have to deal with is that consecutive
parameters aren't necessarily found at consecutive addresses,
since only certain types (and a limited number) are passed in
the registers (the rest go on the stack like any normal machine).