Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > cascading stdarg calls

Reply
Thread Tools

cascading stdarg calls

 
 
cornelis van der bent
Guest
Posts: n/a
 
      11-27-2009
Hi, the code below prints a garbage "world" value to <messages>;
"Hello " is fine. What can be the problem?

static char messages[LARGE_ENOUGH];

int writeText(char* text, char* format, ...)
{
va_list argumentList;

va_start(argumentList, format);
vsprintf(text, format, argumentList);
va_end(argumentList);
}

void writeMessage(char* format, ...)
{
va_list argumentList;

va_start(argumentList, format);
writeText(protocolText, format, argumentList);
va_end(argumentList);
}

void test(void)
{
writeMessage("Hello %s!\n", "world");
}

Thanks,

Cornelis
 
Reply With Quote
 
 
 
 
cornelis van der bent
Guest
Posts: n/a
 
      11-27-2009
On 27 nov, 15:55, Giacomo Degli Esposti
<(E-Mail Removed)> wrote:
> The problem is that you cannot call a function with "..." passing
> it a va_list. You have to create a function accepting a va_list
> as argument.


Thanks for the quick answer! It's already in my code now and of
course works.

Cornelis
 
Reply With Quote
 
 
 
 
cornelis van der bent
Guest
Posts: n/a
 
      11-27-2009
On 27 nov, 15:59, Ben Bacarisse <(E-Mail Removed)> wrote:
> cornelis van der bent <(E-Mail Removed)> writes:
>
> > Hi, the code below prints a garbage "world" value to <messages>;
> > "Hello " is fine. *What can be the problem?

>
> This is a FAQ:http://c-faq.com/varargs/handoff.html
>
> You have to read the linked FAQs first.


Thanks for pointing this out. Apologies! I did search google for a
short period but without succes, but had forgotten to look in the good
old C-FAQ.

Cornelis
 
Reply With Quote
 
Seebs
Guest
Posts: n/a
 
      11-28-2009
On 2009-11-27, cornelis van der bent <(E-Mail Removed)> wrote:
> Hi, the code below prints a garbage "world" value to <messages>;
> "Hello " is fine. What can be the problem?


A va_list is not the same as a series of arguments. You need to use
a va_list argument to writeText, not a ...

-s
--
Copyright 2009, all wrongs reversed. Peter Seebach / http://www.velocityreviews.com/forums/(E-Mail Removed)
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
template with stdarg: enum problem Klaus Schneider C++ 8 10-12-2005 04:14 PM
Confusion with stdarg Mac A. Cody C Programming 9 01-04-2005 02:11 PM
Using stdarg with unknown types Clint Olsen C Programming 6 10-29-2003 06:24 AM
Equivalent of stdarg.h but on the calling side ? Francesco Bochicchio C Programming 5 07-04-2003 09:05 PM
cascading method calls on an object =?ISO-8859-1?Q?Thomas_Gagn=E9?= Java 1 07-02-2003 10:36 PM



Advertisments