int SomeFunction(void)
{
int MyVar;
<Body code sets MyVar = one of 0,1,2,3,4>
return(MyVar);
}
<elsewhere>
int RetVar;
RetVar = SomeFunction; //error here
< more code using RetVar expecting small value>
totally fails because RetVar = 16586 or some similar value
I had missed off the () after SomeFunction
but there is no complaint from the compiler unlike missing ';'
Turn up the compiler warnings in File --> Preferences. You'll probably then see it complaining about assigning a function pointer to an int -- or some such;
Thanks.
I did wonder whether I was getting a pointer rather than the correct return value.
The value was quite consistent between runs.
My code should have returned 0, 1, 2, 3, or 4 as error codes - 0 being no error.
The value seen is way out of the expected range.
I would have thought you needed to be a bit more definite about getting the pointer to a function if indeed that is what it is - maybe it is a pointer to the result or a compiler object reference?
The function name did not occur anywhere else as a variable or other object so I would have expected some sort of 'undefined' warning when allocating it to a variable.
Posting the whole code would not have given any more info as I had solved the problem with the code but was asking why there was no compiler error as I would have expected.
I now know this language needs the '()' when calling a function.
So, what did the compiler say when you set compiler warnings to "All"? We can't tell because you didn't post enough code to actually compile. Also, you didn't tell us what board you're compiling for. Also, you didn't tell us which version of the Arduino IDE you're using. Also, you didn't tell us which version of the board package you're using. I'm not really into guessing game.
I get a compiler error. I have warnings turned up to "All" and I think I even modified the platform.txt file to get rid of where they tell the compiler to make a bunch of errors into warnings.
Arduino: 1.8.10 (Mac OS X), Board: "Arduino/Genuino Uno"
/Users/john/Documents/Arduino/sketch_nov08a/sketch_nov08a.ino: In function 'void setup()':
sketch_nov08a:16:12: error: invalid conversion from 'int (*)()' to 'int' [-fpermissive]
RetVar = SomeFunction; //error here
^~~~~~~~~~~~
exit status 1
invalid conversion from 'int (*)()' to 'int' [-fpermissive]
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.