Function declarations put within comments.

I've encountered a bug in the Arduino environnement, which may lead people who are unaccustomed to C or stupid compiler errors into bad trouble.

It happened that Arduino, when doing its preprocessing, put the functions declarations within a multiline comment starting at the middle of a line. For example, original code :

#define SOME_CONSTANT           /* Writing some stuff about that constant,
which goes along multiple lines  */

Generated code :

#define SOME_CONSTANT           /* Writing some stuff about that constant,
void setup();
void loop();
double someotherfunction();
void etc, etc, etc.
which goes along multiple lines  */

(As I'm stupid, and was tired and late in my work, I haven't kept the original code - I can try to reproduce the error if it might help).

Thanks for the report. My hand-rolled tokenizer misses a few edge cases and that's one of them. I'll try to fix it. If anyone's interested, the code is in: Arduino Starter Kit kaufen [verschiedene Ausführungen] and I started working on some test cases here: Arduino Starter Kit kaufen [verschiedene Ausführungen]. There are definitely a lot of cases missing (and I'm only testing one of the functions!).

What about just adding the declarations at the beginning of the file, right after the include (WProgram.h) ? It would then be easy to locate function declarations by users and tell them not to do it... (datatype or void - some alphanumeric chars - "()" - ";", all this before the first opening brackets.)

A few more things, btw, but they're just my opinion :

Shouldn't compiler warnings be enabled by default, even if the standard Arduino libs issues some while compiling ? - these can be easily disabled, and warnings are far from useless in a general matter.

And it seems that the Arduino lib is recompiled at every build... Is this really needed, too ?

Just adding my two cents, no bad criticism ^^

The reason I'm putting the generated declarations after pre-processor directives (and comments) is so that they can have return types or parameters whose types are defined in a header file (e.g. in another tab in a sketch).

I think warnings are more likely to confuse people than help them, although I may be wrong. I haven't seen many forums posts of people asking for help with things that seem like they would have been avoided with a compiler warning, though.

We probably don't need to recompile the libraries every time, but it makes it easier for people to experiment with changing the code.

I think warnings are more likely to confuse people than help them, although I may be wrong. I haven't seen many forums posts of people asking for help with things that seem like they would have been avoided with a compiler warning, though.

Ok, maybe I'm the only one :slight_smile: I just took me a little time to figure out I was assigning the result of millis() to an int, making the program stop working after a very short amount of time.

We probably don't need to recompile the libraries every time, but it makes it easier for people to experiment with changing the code.

I was thinking about the Arduino library (core.a), which is very unlikely to be modified by users. No big deal, anyway, except maybe on small computers...

Thanks for all your answers,
T.