Understanding a part of a function

Hello all,

I have been studying C++, but am still a novice. While loading up free to use source code to experiment with on my Arduino, I keep getting an error in one expression.



void motor_turn_to_direction(pos_t *current, dir_t dir)
{
if (current->direction == dir)
{
return;
}
else if (position_right_adj_direction(current->direction) == dir)
{
motor_turn_right(stepper0, stepper1);
}
else if (position_left_adj_direction(current->direction) == dir)
{
motor_turn_left(stepper0, stepper1);
}
else
{
motor_turn_180(stepper0, stepper1);
}
}


It is giving me the error "Too many arguments to function". When I comment this particular function out, the code complies correctly, so I know it must be a problem with this function.

Does anyone have any advice? I have been trying to find information on the internet but I am afraid my understanding of functions is still rather simplistic.

Thanks for your help

Last edited on
this error means what it says.
if you have a function
foo (int x, int y)
and you call it with

foo (x,y,z); //you get this error.

so somewhere you are calling a function with more stuff than it is prepared to accept.

Which line exactly did you comment out? Look at that function's header, and compare the parameters you are sending against what it expects.





It compiles only if I comment out the entire function, or if I comment out each part of the "if else" statement except for the first if statement.
try to narrow it down. One of those function calls is wrong. I cant see the other functions....

comment out the function calls one by one until you find it. This is terrible, but the code is small enough that its possible
It is giving me the error "Too many arguments to function"

Your compiler almost certainly gave you more information than that, including a line and column number.

Try to use the information it gives you.
I am using the Arduino IDE to compile it, which gives very little information. I will try to find something that gives more detail.
Arduino C++ does not fully support all C++ things, FYI. It has some macros specific to the hardware and lacks support for a number of standard c++ things.


This is unrelated to your problem, but it does mean that you will need to study the documentation for your hardware. Ive used the platform but it was many years ago. Because of this you can't really move the code to another compiler to syntax check it.
Last edited on
Jonnin wrote:
Arduino C++ does not fully support all C++ things, FYI. It has some macros specific to the hardware and lacks support for a number of standard c++ things. [...] Because of this you can't really move the code to another compiler to syntax check it.

Atmel provides a port of GCC and a header-only library (avr.h et al.) which define the macros you're referring to. There is no C++ standard library, obviously, because the target hardware is freestanding.

Besides the standard library, almost all of the core language features will be available.

You can see the compiler command line by changing some option in the Arduino GUI. The Arduino IDE's front-end does some cursory processing on your source code to make it a valid C++ program and then invokes avr-g++, which is perfectly capable of giving you sufficient information. You may have to invoke the compiler manually, though, if the output is still filtered -- I expect that turning on the "verbose" setting will disable that as well.

The only obstacle to doing things manually is that the Arduino IDE slightly transforms it's input so that a valid Arduino program is not necessarily valid C++: the changes are minor, though.
Topic archived. No new replies allowed.