vprintf/vsprintf with function calls as arguments? 
Author Message
 vprintf/vsprintf with function calls as arguments?

Hi,

I have the following function:

void log(char * str, ...){

 va_start(vararglist, str);
 vprintf(buffer, str, vararglist);
 va_end(vararglist);

Quote:
}

Now when I call

log("%d %d", 1, f(1));

where f is some function int f(int ), the second argument printed by vprintf
appears to be not the output of f(1). (Sorry for the roundabout explanation,
but this is a whittled down example of the real code.)

Is there a known problem with a call to vprintf(str, format), where format
contains calls to functions (such as f(.) above)?

i and a colleague gone over the code several times, and it doesn't make
sense that this is happening inside visual studio.

Thanks in advance.

Indranil



Sun, 20 Feb 2005 06:36:09 GMT  
 vprintf/vsprintf with function calls as arguments?

Quote:

>Hi,

>I have the following function:

>void log(char * str, ...){

> va_start(vararglist, str);
> vprintf(buffer, str, vararglist);
> va_end(vararglist);

>}

>Now when I call

>log("%d %d", 1, f(1));

>where f is some function int f(int ), the second argument printed by vprintf
>appears to be not the output of f(1). (Sorry for the roundabout explanation,
>but this is a whittled down example of the real code.)

>Is there a known problem with a call to vprintf(str, format), where format
>contains calls to functions (such as f(.) above)?

>i and a colleague gone over the code several times, and it doesn't make
>sense that this is happening inside visual studio.

The function log() can't compile as written, and you're calling
vprintf as if it was vsprintf. Try to whittle it down to a compilable
example that demonstrates the problem.

--
Doug Harrison
Microsoft MVP - Visual C++



Sun, 20 Feb 2005 08:12:32 GMT  
 vprintf/vsprintf with function calls as arguments?

Quote:
> The function log() can't compile as written, and you're calling
> vprintf as if it was vsprintf. Try to whittle it down to a compilable
> example that demonstrates the problem.

> --
> Doug Harrison
> Microsoft MVP - Visual C++

Thanks Doug. I appologize -- I realized the problem was not with
vprintf/vsprintf, but with inet_ntoa using a static buffer.

Indranil



Mon, 21 Feb 2005 08:31:22 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. vsprintf - how to determine number of arguments

2. calling unmanaged function with variable list of arguments (ellipses) failed

3. Calling a function with variable # arguments

4. Optional argument in function call

5. HDI: call an arbitrary function with an arbitrary number of arguments (and possibly arbitrary types)

6. passing a function as an argument, then calling it

7. calling function with different number of arguments at runtime

8. recursively calling char *functions with char *arguments

9. Too many arguments in function call

10. evaluation order: function call arguments

11. Function is called with different type of arguments than declared

12. Call a varargs function with dynamic number of arguments

 

 
Powered by phpBB® Forum Software