Pass all arguments from outer function to inner function C

93 Views Asked by At

How would I go about passing all arguments to an inside function? I cannot find an answer anywhere for C.

Here's the basic idea of what I'm trying to do:

void customPrint(arguments) {
  Serial.print(arguments);
  Serial.print(arguments);
}

I've tried argc/argv syntax as well as ... syntax but cannot figure it out.

2

There are 2 best solutions below

0
gulpr On

You need a function which accepts a va_list argument. None of the Arduino print variants accept this type of argument.

So it is not possible.

0
datafiddler On

the basic idea of what I'm trying to do

does not fit to your question.

If you want a customPrint function, which calls various overloads of the Stream::print method, you have to implement those overloaded functions.

void customPrint( double val, uint_8t digits=2);
void customPrint( long val, uint_8t base = 10);  

etc.

BTW: Hiding Serial inside that function isn't very smart, IMHO.

The other answer "So it is not possible" is correct as well, regarding your question.