home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!usc!cs.utexas.edu!sun-barr!ames!saimiri.primate.wisc.edu!hp9000.csc.cuhk.hk!hkuxb.hku.hk!h8915726
- From: h8915726@hkuxb.hku.hk (Medusa)
- Subject: Re: Variable argument list question
- Message-ID: <BzEqEC.MuI@hkuxb.hku.hk>
- Reply-To: h8915726@hkuxa.hku.hk
- Organization: University of Hong Kong
- X-Newsreader: Tin 1.1 PL4
- References: <1992Dec15.182906.25072@ugle.unit.no>
- Date: Thu, 17 Dec 1992 14:18:11 GMT
- Lines: 75
-
- bjornw@colargol.edb.tih.no (Bjoern Wennberg) writes:
- : Hi!
- :
- : I am trying to make a function that
- : 1. Has an variable argument list
- : 2. Manipulates the arguments that the argument list points to
- :
- :
- : Here is an example which illustrates the problem:
- :
- : int main(void)
- : {
- : char *flag;
- : func(flag);
- : /* flag == "test" */
- : }
- :
- : void func(...)
- ^^^^^^^^
- I'm not sure if it's gonna work, in PC, args should initially
- point to the last _fixed_ argument. If there is not fixed argument,
- I don't know. In fact, probably you may want to pass how many
- parameters in the variable argument list.
-
- e.g. func (int n, ...)
-
- Otherwise, you never know when to stop. (Or you give a extra NULL as
- terminating signal).
-
- : {
- : va_list args;
- : va_start(args, "%s");
- :
- : va_arg(args, char *);
- :
- : /* allocate space for 'flag' by using 'args' */
- : /* manipulate 'flag' by using 'args' */
- :
- : /* *args = new char[10]; doesn't work*/
- : /* args = new char[10]; doesn't work*/
- : /* memcpy() / strcpy() and friends doesn't work */
- :
- : /*
- : * debugger show me that 'args' points to the same address as 'flag'
- : * does. But I cannot insert anything inside this address.
- : */
- : va_end(args);
- : }
- :
- : Any comments are welcome.
- :
- : bjornw>
- : --
- : bjornw@edb.tih.no Bjoern Wennberg Trondheim College of Engeneering
- :
-
-
- You can also try, directly, if you have:
-
- func (int n, ...)
-
- double *f;
-
- f = &n;
-
- and then manipulate f...(but I think it's not very safe).
-
- Any comment welcome.
-
-
- --
- Medusa
- University of Hong Kong
- H8915726@hkuxa.hku.hk
-
-