Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
* More porting problems, function arguments.
@ 1994-04-11 11:21 Chris Johnson
  1994-04-11 22:12 ` Eric Osborne
  0 siblings, 1 reply; 2+ messages in thread
From: Chris Johnson @ 1994-04-11 11:21 UTC (permalink / raw)


     in K&R implementations it was possible to have a variable number of
function arguments, in other words different numbers of arguments for
different function calls to the same function.  A good example of this
is printf.  The printf function can have as man aguments as you want
determined by the first argument formatting string.  

     I'm trying to port old C, K&R filled with BSDisms, to OSF 1.  There
is one call in this code used many places that relies on te fact that
older compilers didn't mind argument number mismatches between function
definition and call.  That is the definition had 10 arguments but the
call supplies only 6.  

     I'm at a point now where the running code dies with a BPT Trap at
this mismathed call.  

     Should this mismatch work in OSF 1' s C?

     Is there a way to do this mismatch?

     This function is used (or misused) all over the place.  I need to
come up with a plan of attack on how to deal with this.

     Thanks.
============================================================================
Chris Johnson                            Internet: johnson@chaos.dac.neu.edu
Assistant Director, Systems              BITNET:   johnson@nuhub
Division of Academic Computing           Voice:    617.373.3300
Northeastern University, 39RI            FAX:      617.373.8600
360 Huntington, Ave.
Boston, MA., U.S.A. 02115
============================================================================


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: More porting problems, function arguments.
  1994-04-11 11:21 More porting problems, function arguments Chris Johnson
@ 1994-04-11 22:12 ` Eric Osborne
  0 siblings, 0 replies; 2+ messages in thread
From: Eric Osborne @ 1994-04-11 22:12 UTC (permalink / raw)


In article <2obbs7$ppv@chaos.dac.neu.edu> johnson@chaos.dac.neu.edu (Chris Johnson) writes:
>     in K&R implementations it was possible to have a variable number of
>function arguments, in other words different numbers of arguments for
>different function calls to the same function.  A good example of this
>is printf.  The printf function can have as man aguments as you want
>determined by the first argument formatting string.  
>
>     I'm trying to port old C, K&R filled with BSDisms, to OSF 1.  There
>is one call in this code used many places that relies on te fact that
>older compilers didn't mind argument number mismatches between function
>definition and call.  That is the definition had 10 arguments but the
>call supplies only 6.  
>
>     I'm at a point now where the running code dies with a BPT Trap at
>this mismathed call.  
>
>     Should this mismatch work in OSF 1' s C?
>
>     Is there a way to do this mismatch?
>
>     This function is used (or misused) all over the place.  I need to
>come up with a plan of attack on how to deal with this.
>
>     Thanks.
>============================================================================
>Chris Johnson                            Internet: johnson@chaos.dac.neu.edu
>Assistant Director, Systems              BITNET:   johnson@nuhub
>Division of Academic Computing           Voice:    617.373.3300
>Northeastern University, 39RI            FAX:      617.373.8600
>360 Huntington, Ave.
>Boston, MA., U.S.A. 02115
>============================================================================


You can do this kind of thing, but you have to be VERY careful.  A lot
of these kinds of function definitions in old code are based on the 
very non-portable assumption that all the arguments to the function, and
all the return values that can be returned, are the same size.  This is 
NOT true on DEC OSF/1 - longs and pointers are twice the size of integers.

The correct way to do this sort of thing is with varargs.  Barring that,
code the function so that all the args and the return value are some
generic type like (void *), then be very careful to cast the args inside
the function before use.  Similarly cast the return value from the function
to the correct type on return.

I know this sounds like a hassle, but the code will be more portable after
it is done.  Even under K&R, the only assumption that could be made was
that sizeof(int) <= sizeof(long), and there was no way at all to relate to
size of pointer types.  A lot of code made those assumptions, but it is 
inherently non-portable.

Eric Osborne
edo@cso.dec.com

===========================================================================
The opinions expressed above are mine alone, but for a small fee they may
possibly become yours as well.  They do not necessarily represent the 
opinions of Digital Equipment Corporation.
===========================================================================

-- 

===========================================================================
The opinions expressed above are mine alone, but for a small fee they may
possibly become yours as well.  They do not necessarily represent the 
opinions of Digital Equipment Corporation.
===========================================================================



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1994-04-11 22:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1994-04-11 11:21 More porting problems, function arguments Chris Johnson
1994-04-11 22:12 ` Eric Osborne

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox