Please forgive me if this is the incorrect place to post a newbie question and if you can, please direct me to the appropriate place if it is not.
I am new to Arduino but have been programming in C++ for many years. Perhaps too many years because I am getting a compiler error in Arduino that my Windows compiler doesn't have an issue with.
This compiles fine in Arduino
I believe that C++ is a free form language where spaces, tabs and newlines do not effect compilation. Does anyone know why I am getting a compile error? The error is strange too.
x.ino:116:8: error: two or more data types in declaration of 'logTemperature' *<-- note that logTemperature is a function much lower down in the code.*
116 | static bool
| ^~~~
x:117:1: warning: ISO C++ forbids declaration of 'afunc' with no type [-fpermissive]
117 | afunc(void)
| ^~~~~
x:117:1: error: ambiguating new declaration of 'int afunc()'
x.ino:114:1: note: old declaration 'bool afunc()'
114 | afunc(void);
| ^~~~~
x.ino:114:1: warning: 'bool afunc()' declared 'static' but never defined [-Wunused-function]
x:114:1: warning: 'bool afunc()' used but never defined
Thank you so much for your reply! It is for the Teensy 4.1 board. I put the error message in the original message but here as well. Also, log Temperature is a function much further down in the code.
x.ino:116:8: error: two or more data types in declaration of 'logTemperature'
116 | static bool
| ^~~~
x:117:1: warning: ISO C++ forbids declaration of 'afunc' with no type [-fpermissive]
117 | afunc(void)
| ^~~~~
x:117:1: error: ambiguating new declaration of 'int afunc()'
x.ino:114:1: note: old declaration 'bool afunc()'
114 | afunc(void);
| ^~~~~
x.ino:114:1: warning: 'bool afunc()' declared 'static' but never defined [-Wunused-function]
x:114:1: warning: 'bool afunc()' used but never defined
I wonder if the 'split' version of the function definition is not recognised by the "special automatic function prototype generator feature" causing yet another prototype to be thrown in.
I can't test it now but the preprocessor compiler output should show if this is the case.
Generating unwanted function return types is almost as bad as generating unwanted function prototypes
Incidentally, this behaviour of automatic function generation was already present in the "Processing" development system on which the Arduino "language" was based. That is, according to deepseek AI.
So the Arduino IDE developers are not necessary to blame for the consequences of all this and need not be too defensive about it IMHO.
The problems caused by the inclusion of the -fpermissive flag in the compilation command templates, and the proposal for removal of the flag are tracked by the Arduino developers here:
The programming language used by Processing is essentially Java (I think they actually do the same as Arduino and consider it to be a new language). I don't know anything about Java, but my understanding is that, unlike C++, function prototypes (AKA "forward declarations") are not used in Java.
It might well be that prototype generation was already in place in the Wiring IDE at the time Arduino forked it though.
I'd forgotten about the "Wiring" phase in the evolution of Arduino. That was all before my time . The lesson anyway is that well meaning efforts, such as those referenced here, to make life simpler for new users have to be very carefully thought through to avoid creating bigger problems in the future.
Interesting is that the small sketch produced by the OP managed simultaneously to demonstrate two of these controversial issues.