Path: utzoo!mnetor!uunet!husc6!bbn!oberon!skat.usc.edu!blarson From: blarson@skat.usc.edu (Bob Larson) Newsgroups: comp.lang.c Subject: Re: problems with varargs Message-ID: <6394@oberon.USC.EDU> Date: 22 Jan 88 07:13:55 GMT References: <7962@eleazar.Dartmouth.EDU> Sender: nobody@oberon.USC.EDU Reply-To: blarson@skat.usc.edu (Bob Larson) Organization: USC AIS, Los Angeles Lines: 57 Keywords: varargs In article <7962@eleazar.Dartmouth.EDU> cmi@eleazar.Dartmouth.EDU (Theo Pozzy/R. Green) writes: >I'm have a problem working with the standard *nix varargs construct. >myprintf(fmt, va_alist) >char *fmt; >va_dcl >{ >va_list vap; >va_start(vap); >/* here I can pull of the arguments with no problem */ >myfprintf(stdout,fmt,vap); >va_end(vap); >} va_alist MUST be the only argument to a varargs function. (Lint (sun 3.2) gets this horrably WRONG. If you don't get a ton of error messages from lint you made a mistake. (This is another case where something non-portable happens to work on 4.2bsd so people assume it works everywhere.) myprintf(va_alist) va_dcl { va_list vap; char *fmt; va_start(vap); fmt = va_arg(vap, char *); myfprintf(stdout, fmt, vap); va_end(vap); } >myfprintf(f, fmt, va_alist) >FILE *f; >char *fmt; >va_dcl >{ >va_list vap; >va_start(vap); >/* at this point, the va_arg() routine doesn't return the arguments correctly */ >va_end(vap) >} This is where your major mistakes are. myfprintf(f, fmt, vap) FILE *f; char *fmt; va_list vap; { /* va_arg should work here */ } Note that you may have to pass a pointer to vap on systems that va_list is a structure but don't have structure passing. -- Bob Larson Arpa: Blarson@Ecla.Usc.Edu blarson@skat.usc.edu Uucp: {sdcrdcf,cit-vax}!oberon!skat!blarson Prime mailing list: info-prime-request%fns1@ecla.usc.edu oberon!fns1!info-prime-request