transfering variable length argument list



 DEVELOP > c-Plus-Plus > transfering variable length argument list

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "ANDERS FLODERUS"
Date: 20 Dec 2003 02:03:01 AM
Object: transfering variable length argument list
Is it possible to transfer a variable length argument
list? What I want to do is just
void myPrintf( char *pFormat, ... ) {
char buf[256];
sprintf( buf, pFormat, ... );
.
.
.
return;
}
which obviously will not compile. If possible, I would
like to do it without using the va_... macros while stepping
throu the format specifier. I suppose it would be possible
althou I do not know what type the arguments are (could
be found in the format specifier?).
Thanks for any answer
Anders
.

User: "Rob Williscroft"

Title: Re: transfering variable length argument list 20 Dec 2003 02:27:31 AM
ANDERS FLODERUS wrote in news:1pTEb.253$pF.349@nntpserver.swip.net:

Is it possible to transfer a variable length argument
list? What I want to do is just

void myPrintf( char *pFormat, ... ) {
char buf[256];
sprintf( buf, pFormat, ... );
.
.
.
return;
}

which obviously will not compile. If possible, I would
like to do it without using the va_... macros while stepping
throu the format specifier. I suppose it would be possible
althou I do not know what type the arguments are (could
be found in the format specifier?).

#include <cstdio>
#include <cstdarg>
void myPrintf( char const *pFormat, ... )
{
using namespace std;
char buf[256];
va_list va;
va_start( va, pFormat );
vsprintf( buf, pFormat, va );
/* _vsnprintf is non standard but your compiler may provide it.
If so its *safer* than the above.
*/
//_vsnprintf( buf, sizeof buf, pFormat, va );
va_end( va );
printf( "buf = [%s]\n", buf );
}
int main()
{
myPrintf("test %d", 1 );
}
HTH.
Rob.
--
http://www.victim-prime.dsl.pipex.com/
.


  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER