home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / c / 18418 < prev    next >
Encoding:
Text File  |  1992-12-15  |  1.2 KB  |  55 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!mcsun!sunic!ugle.unit.no!bjornw
  3. From: bjornw@colargol.edb.tih.no (Bjoern Wennberg)
  4. Subject: Variable argument list question
  5. Message-ID: <1992Dec15.182906.25072@ugle.unit.no>
  6. Sender: news@ugle.unit.no (NetNews Administrator)
  7. Organization: Colargol, Trondheim College of Engineering
  8. X-Newsreader: TIN [version 1.1 PL8]
  9. Date: Tue, 15 Dec 92 18:29:06 GMT
  10. Lines: 43
  11.  
  12. Hi!
  13.  
  14. I am trying to make a function that 
  15.     1. Has an variable argument list
  16.     2. Manipulates the arguments that the argument list points to
  17.  
  18.  
  19. Here is an example which illustrates the problem:
  20.  
  21. int main(void)
  22. {
  23.   char *flag;
  24.   func(flag);
  25.   /* flag == "test" */
  26. }
  27.  
  28. void func(...)
  29. {
  30.   va_list args;
  31.   va_start(args, "%s");
  32.   
  33.   va_arg(args, char *);
  34.   
  35.   /* allocate space for 'flag' by using 'args' */
  36.   /* manipulate 'flag' by using 'args' */
  37.   
  38.   /* *args = new char[10];  doesn't work*/
  39.   /* args = new char[10];  doesn't work*/
  40.   /* memcpy() / strcpy() and friends doesn't work */
  41.  
  42.   /* 
  43.    * debugger show me that 'args' points to the same address as 'flag'
  44.    * does. But I cannot insert anything inside this address.
  45.    */
  46.   va_end(args);
  47. }
  48.  
  49. Any comments are welcome.
  50.  
  51. bjornw>
  52. --
  53. bjornw@edb.tih.no     Bjoern Wennberg     Trondheim College of Engeneering
  54.  
  55.