Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!wuarchive!uunet!mcsun!ukc!icdoc!qmw-dcs!liam From: liam@dcs.qmw.ac.uk (William Roberts;) Newsgroups: comp.unix.aux Subject: Re: Porting MPW C code to A/UX, Can some one give me a hand? Message-ID: <3134@redstar.dcs.qmw.ac.uk> Date: 11 Jun 91 15:48:45 GMT References: <1991Jun6.071753.4907@newshost.anu.edu.au> Sender: usenet@dcs.qmw.ac.uk Lines: 66 Nntp-Posting-Host: whitesand.dcs.qmw.ac.uk In <1991Jun6.071753.4907@newshost.anu.edu.au> djp862@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 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@dcs.qmw.ac.uk % Queen Mary & Westfield College UUCP: liam@qmw-dcs.UUCP % Mile End Road Telephone: +44 71 975 5234 % LONDON, E1 4NS, UK Fax: +44 81-980 6533