Porting MPW C code to A/UX, Can some one give me a hand?

William Roberts; liam at dcs.qmw.ac.uk
Wed Jun 12 01:48:45 AEST 1991


In <1991Jun6.071753.4907 at newshost.anu.edu.au> djp862 at anu.oz.au ("David J 
Peterson") writes:


>In MPW the function are prototyped as:

>function( int, ... )	/* one int, and then none to ? _ints_ */

This is official ANSI notation for a function which takes one or more 
arguments of which the first is definitely an integer.

>then in the function definition:

>#define PARM	, var
>#define DECL	int var;

>function( int, PARM )
>  int anInt;
>  DECL
>{
> ...
>}

This is *NOT* ANSI C. I suspect it goes on to do bizarre things to get at the 
second and subsequent arguments. The correct ANSI C way of defining the 
function would be something like:

#include <stdarg.h>

void myfunction(int fixed, ...)
{
    va_list ap;             /* used to get at the extra arguments */
    int ival1, ival2;
    
    va_start(ap, fixed);    /* make ap point to first unnamed arg */
    switch(fixed) {
    case 2:
       ival1 = va_arg(ap, int);
       ival2 = va_arg(ap, int);
       goto varargs_cleanup;
    /* more cases */
    }
varargs_cleanup:
    va_end(ap);             /* NB. this is MANDATORY */
}

There is an example in the 2nd Edition of K&R, and some more stuff in an 
appendix.


>The functions are expecting a list of integers (not a character
>string) to be passed as the variable argument list. MPW C has no
>problem compiling this, but A/UX cc (and gcc) just choke

As they should - your code has evil MPW-specific hacks in it.
There isn't an easy answer: you will have to pick either A/UX cc or gcc and 
then convert the MPW code to work with your chosen compiler.

I'd be inclined to choose gcc: it is a better compiler and Apple must 
eventually produce an ANSI C compiler as well.
--

% William Roberts                 Internet:  liam at dcs.qmw.ac.uk
% Queen Mary & Westfield College  UUCP:      liam at qmw-dcs.UUCP
% Mile End Road                   Telephone: +44 71 975 5234
% LONDON, E1 4NS, UK              Fax:       +44 81-980 6533



More information about the Comp.unix.aux mailing list