Function with optional argument(s)

Hey everyone.

I'm trying to write a function with optional arguments.

for example (pseudo-code)

void myFunction(boolean option){
  if option is not defined
    do some default action
  if option is defined
    if option
      action for option==true
      action for option==false

i know that the Serial.print function will take optional arguments for printing various output formats.

I hope i'm not asking a blatantly obvious question, and I have tried to search the forum and 'interwebs' for a solution... no luck!

-so could someone please point me in the right direction for how to define an optional argument for a function call?

Thanks in advance for yor time :)

I'm not sure if it works on the Arduino, but the usual way, in C/C++, is like this:

Function prototype:

functionReturnType FunctionName(optionalArgType optArg = defaultValue);


functionReturnType FunctionName(optionalArgType optArg)
   // optArg will have default value, unless one is supplied


FunctionName(); // Use the default value
FunctionName(42); // Use specific value

I think you need to overload the function. I suppose like this from the print.cpp file

void Print::print(const char str[])

void Print::print(char c, int base)
  print((long) c, base);

void Print::print(unsigned char b, int base)
  print((unsigned long) b, base);

Thanks PaulS. that worked.

pracas>> i'm not sure how it works, defining multiple functions by the same name, but with different arguments. :-?

Anyway. thanks for your replies. I think i'll be able to do what I intended 8-)

That is called overloading.