home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!usc!zaphod.mps.ohio-state.edu!uwm.edu!ogicse!henson!n8743196
- From: n8743196@henson.cc.wwu.edu (Jeff Wandling)
- Newsgroups: comp.lang.c
- Subject: Re: Multiple Parameter Passing (unspecified number)
- Message-ID: <1992Nov17.105837.21867@henson.cc.wwu.edu>
- Date: 17 Nov 92 10:58:37 GMT
- Article-I.D.: henson.1992Nov17.105837.21867
- References: <92321.124834GNR100@psuvm.psu.edu> <1992Nov17.093123@rbg.informatik.th-darmstadt.de>
- Organization: Howling Dog
- Lines: 52
-
- misar@rbg.informatik.th-darmstadt.de (walter misar) writes:
-
- >In article <92321.124834GNR100@psuvm.psu.edu>, <GNR100@psuvm.psu.edu> writes:
- >> Hi.
- >>
- >> I'm looking to write a function that accepts any number of paramerter.
- >> There will be at least two, an int and a char[]. The rest will all be char[]'s.
- >> I need to know how this is done. The meathod would be similar to that of
- >> printf(), so if anybody know how that works, please let me know.
-
- >If you use an ANSI compiler it will look like this:
-
- >#include <stdarg.h>
-
- >void fun(int i,char s[],...) /* 3 dots exactly */
- >{ va_list argp;
- > /* more variables */
-
- > va_start(argp,s); /* 2nd arg is last named fun-arg */
- > /* with va_arg(argp, TYPENAME) you can step through the arg-list,
- > the macro will provide always the next one, TYPENAME is the type
- > of the arg (in this case char * or char [])
- > */
- > /* some code */
- > va_end(argp);
-
- >}
-
- System: Sun 3/50, SunOS 4.1.1b
-
- I'm trying to do a similar thing, except my function doesn't know what type
- to expect. The next "variable argument" could be any simple type. How
- do I deal with this? Is there a way to switch on the type of the next
- argument? When using union's for example---
-
-
- hash_insert(table,name,...)
- ....
- {
-
- ....
- va_list argp;
-
- type = va_"type?"(argp,???);
-
- ....
- }
-
- --
- perl -e '$a="Japhuneasorcttlk h eae r r ,";$]=0;$s=$];while($s<4){do{$_ .= pack
- ("c",vec($a,$],8));$]+=4;}while($]<length($a)&&vec($a,$],8)!=32);$s++;$]=$s;$_
- .= ' ';}chop;print;' Jeff Wandling <jdw@physics.wwu.edu> "will hack for food"
-