Hi Michael,
Looking at your code:
long to_steps(float steps_per_unit, float units);
{
return(steps_per_unit * units);
}
there shouldn't be a semi-colon on the end of the function definition. I'm assuming this is just a transcription typo for now, but it may indicate the code you are posting is not the same as giving the errors.
So, I made a simple program:
long to_steps(float steps_per_unit, float units) {
return(steps_per_unit * units);
}
int main() {
return to_steps(1.0, 3.5);
}
which compiles fine. Note, I wouldn't recommend using "long"; "int" is much more preferable in a standard C/32-bit world. So the function would look like:
int to_steps(float steps_per_unit, float units) {
return (steps_per_unit * units);
}
The function multiplies two floating point values together, then (implicitly) casts them to an int(eger) as that is what the return type is - I assume that is what you were after? Other than this minor change and the semi-colon, it looks fine.
Your second code snippit looks fine too, except again it uses types "long" and "byte" (byte is not a C type). I'd change these to "int" and "char" and it should compile fine. int is the "generic" integer variable to use as a rule of thumb.
The error you are getting sounds like there is a mismatch of types somewhere, but i'm not sure it is these functions. Have a little more investigation, and see if you can find out any more. btw, the error messages say what file/line the error is on in case you had missed that.
Simon
Hi,
I am trying to port some code I use on an Arduino to my new mbed!!
The following
Gives an error E120 Return value type does not match the function type? It worked on an Arduino what am I missing?
also with a boolean statement;
I get the same error with the above? Why is return false / true not the right return value for a bool function? Again I'm sure its something I'm doing wrong as I am still quite new to C!!!!
Thanks
Michael.