Path: chuka.playstation.co.uk!news From: James Russell Newsgroups: scee.yaroze.programming.libraries Subject: Re: Variable arg list Date: Fri, 27 Nov 1998 11:05:00 +0000 Organization: Sony Computer Entertainment Europe Lines: 62 Message-ID: <365E875C.8B7B87FD@scee.sony.co.uk> References: <73lri0$ngl1@chuka.playstation.co.uk> NNTP-Posting-Host: mailgate.scee.sony.co.uk Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 4.5b2 [en] (Win95; I) X-Accept-Language: en ROBERT C SHAND wrote: > > Hi all, > > Is it possible to setup a variable arg list for functions?, such a those > found in printf, on the yaroze. I know these form part of the standard libs > (as in ANSI) but we only have a subset of these. Yes - it's fairly easy. Here's an example: Remember - there's no variable that states how many extra args you have - it has to be specified either implicitly (as in printf) or explicitly in one of the fixed args. This is a pretty useless function, but hopefully you get the idea. #define va_start(AP, LASTARG) \ (AP = ((char *)&(LASTARG) + __va_rounded_size(LASTARG))) #define va_end(AP) AP = (char *)NULL #define va_arg(AP, TYPE) \ (AP = ((char *) (AP)) += __va_rounded_size (TYPE), \ *((TYPE *) ((char *) (AP) - __va_rounded_size (TYPE)))) typedef void *va_list; // Convert all passed strings to upper case before printing. // usage: // printff("Abcdef : %s abc: %d",myString,100); // follow this with. // printf("Abcdef : %s abc: %d",myString,100); void printff(char *s, ...) { va_list ap; int argnum; char *p,**a; static char strbuffer[1000]; va_start(ap, s); argnum = 0; a = (char **)ap; for(p = s; *p != 0; p++) { if(p[0] == '%') { if(p[1] == 's') { makeUpperCase(a[argnum]); } argnum++; p++; } p++; } a = (char **)ap; va_end(ap); } -- == James_Russell@scee.sony.co.uk +44 (171) 447-1626 == Developer Support Engineer - Sony Computer Entertainment Europe Programming is an art form that fights back.