External function with optional parameter declaration

I have the following code


#include "functions.h"
int foo(int 1, in 2);
int foo(int 1, int2, int 3);



//versin 1
void foo(int a, int b, int c);
//version 2
void foo(int a, int b, int c=0);



int x:

void foo(int a, int b, int c=0);
x = a+b+c;

but I get errors
with version 1 in the header file I get too may arguments in main.cpp
with version 2 in the header file I get default argument given for parameter 3 of void 'foo(… in functios.cpp
after previous specification in void 'foo(…
in functions.h

How else?
Thanks for help

What is supposed to do? Declare the function? Call it? This is not valid C/C++ syntax.

Both of these function declarations are okay on their own, but default parameters are only allowed in the declaration, not in the definition. So in the functions.cpp,

the int c=0 is invalid, that must be int c.

Also, in relation to the first question:

it looks like you declare foo to be of return value type int, but the implementation and other header file declares it as void. The result of a+b+c is stored in a global variable x and not given as the return value – are you sure that that’s what you want?

Thanks for quick response. Sorry I did a mistype there is no return parameter so it should be foo(1, 2); and food(1, 2, 3);
in the first line the default parameter value = 0 should be used in the second the passed parameter value 3.
I omittdet the =0 ind the header and have it only in the cpp file. But I get the error too few arguments in main.cpp

Please show your exact main.cpp code.

I posted here just an example, the problem is i a project with over a 1000 lines of code and this is the last compile error. I will create an extract with the problem, give me a bit of time

]#include <Arduino.h>
#include “func.h”

void setup() {
// put your setup code here, to run once:

void loop() {
// put your main code here, to run repeatedly:
test(1, 2);


#ifndef FUNC_H
#define FUNC_H
void test(int a, int b, int c);


#include "func.h"
int x;
void test(int a, int b, int c=0)
  x= a+b+c;

Error message
src/main.cpp: In function ‘void loop()’:
src/main.cpp:10:12: error: too few arguments to function ‘void test(int, int, int)’
test(1, 2);
In file included from src/main.cpp:2:0:
src/func.h:4:6: note: declared here
void test(int a, int b, int c);
*** [.pio/build/esp12e/src/main.cpp.o] Error 1

The function declaration in the header must have the default parameter int c=0, the function implementation in the cpp file must not have that, aka it must use int c.

Thanks that works. I tried some versions, but this one was the least I assumed.
Thanks a lot