delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/09/28/15:15:22

From: "A. Jans-Beken" <jansb000 AT wxs DOT nl>
Newsgroups: comp.os.msdos.djgpp,rec.games.programmer,alt.games.programming
Subject: Help with variable argument-list (va_list)
Date: Thu, 28 Sep 2000 21:00:03 +0200
Organization: World Access
Lines: 44
Message-ID: <39D39533.33F46DA4@wxs.nl>
NNTP-Posting-Host: ipc3797b69.dial.wxs.nl
Mime-Version: 1.0
X-Trace: reader3.wxs.nl 970167011 13271882 195.121.123.105 (28 Sep 2000 18:50:11 GMT)
X-Complaints-To: abuse AT wxs DOT nl
NNTP-Posting-Date: 28 Sep 2000 18:50:11 GMT
X-Mailer: Mozilla 4.7 [en-gb] (Win98; I)
X-Accept-Language: en
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

I am trying to create a wrapper for a function that uses a variable
argument list (like printf).
I have tried the code below, and the first argument works, but not the
second.
What is wrong in this example?
(the program compiles with DJGPP 2.95)

// ---- 8< ---- 8< ----
// file: test.cpp

#include <iostream>
#include <stdio.h>
#include <stdarg.h>


void test_me(char *fmt, ... ) {
   va_list ap;
   va_start(ap,fmt);
   printf(fmt,va_arg(ap,va_list));
   va_end(ap);
   }

int main() {
   cout << "Test of va_list and co...\n";
   cout << "=========================\n\n";

   printf("The printf() function is working fine.\n");

   int i = 3;
   char *s = "Hello dear people";

   // The function test_me is a wrapper for printf.
   // How can I wrap a function with a variable number
   // of parameters?
   test_me("My arguments are %d and %s\n",i,s);

   return 0;
   }
// ---- 8< ---- 8< ----

Please send answers to "jansb000 AT wxs DOT nl"



- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019