1

I have looked up this question: How to pass argument got from ellipsis operator to other function?

But it can't be applied here:

void foo(const char *, ...); //call printf
void bar(const char *, ...); //call foo

I want something like this:

void bar(const char *format, ...){
  foo(format, ...);
}

I know I can use vprintf for printf but there's no similar vfoo for foo

How?

Community
  • 1
  • 1
DMaster
  • 603
  • 1
  • 10
  • 23
  • Look at `vfprintf()` et al — you pass a `va_list`. There's a duplicate; I'm off to find it... – Jonathan Leffler Jun 15 '15 at 01:15
  • It looks like the real question here might be how to implement a `void vfoo(const char *, va_list args)`. – Greg Hewgill Jun 15 '15 at 01:16
  • `printf` have `vprintf` but `foo` don't have `vfoo` – DMaster Jun 15 '15 at 01:18
  • So I'm guessing you can't make a `vfoo` taking a `va_list`? – chris Jun 15 '15 at 01:24
  • As the question to which I've made this a duplicate says, you need to create the `vfoo()`. You will modify your existing `foo()` to call `vfoo()` as an internal implementation detail, but the vast majority of the code from `foo()` will transplant to `vfoo()` and what's left in `foo()` will be a tiny stub that translates from `...` to `va_list`. – Jonathan Leffler Jun 15 '15 at 01:24
  • See also some of the other questions in the 'related' list at the RHS of the page. Sadly, the highest voted question [Passing variable number of arguments around](http://stackoverflow.com/questions/205529/passing-variable-number-of-arguments-around) is a little shambolic in presentation, for all it has a lot of votes. – Jonathan Leffler Jun 15 '15 at 01:34
  • the solution to this problem in C and C++ is quite different. Are you programming in C, C++ or the intersection of the two? – Yakk - Adam Nevraumont Jun 15 '15 at 01:34
  • @Yakk please tell me what's the difference. Also, can I apply the solution from C to C++? – DMaster Jun 15 '15 at 01:51
  • I asked a pretty clear questions about your problem. You have not answered it. If you answer it, I may have followup questions. If you do not have an actual practical problem, or do not feel like answering my questions to find a possibly better solution, feel free to continue not answering my questions. – Yakk - Adam Nevraumont Jun 15 '15 at 02:08
  • @Yakk you told me that the solution to C and C++ is quite different. I'm a C++ programmer. I wonder if there's some solutions in C++ better than in C. – DMaster Jun 15 '15 at 02:35
  • @DMaster, Likely variadic templates. – chris Jun 15 '15 at 04:43
  • @DMaster sounds like an XY problem. In C++ you wouldn't use `...` in the first place. – M.M Jun 15 '15 at 05:31

0 Answers0