EPIC FAIL: automatic function prototype generation

Until recently I had been using version 1.6.3 of the Arduino IDE but in order to use a specific Core add-on I unfortunately had to "upgrade" to version 1.6.4.

My code introduces a "Display" class (defined in a separate tab) and in my main sketch I had defined
a utility function (which I export to various other classes that I've defined in separate tabs):

void dbgTrace(Display *d, const char* m) {
...
}

This used to work fine in version 1.6.3 but starting from the "shitgrade" to 1.6.4 the code no longer compiles but I am getting idiotic error messages. I looks as if the IDE is now automatically generating
garbage function prototypes that it then doesn't know how to deal with..

I found the below braindead workaround for this issue:

void dbgTrace(void *d, const char* m) {
  Display *display= (Display*)d;
}

But is this crazy shit just a problem of version 1.6.5 or would I need to expect the same when upgrading to even newer versions?

I know it works with 'enum' Perhaps this would also work with 'class':

void dbgTrace(class Display *d, const char* m) {
...
}

The prototypes are getting added before the declaration of "Display" so the type is unknown. Perhaps if the compiler is told the pointer is to a 'class' it won't worry that 'Display' is not yet defined.

yes, that also seems to be a functional workaround

Also check behavior on 1.6.9 - 1.6.6 and later have a new build process (1.6.6-1.6.8 all have nasty bugs of some kind or another though, so use 1.6.9). Though I thought the automatic function prototype generation was said to be worse on arduino builder than the old build system...

DrAzzy:
Also check behavior on 1.6.9 - 1.6.6 and later have a new build process (1.6.6-1.6.8 all have nasty bugs of some kind or another though, so use 1.6.9). Though I thought the automatic function prototype generation was said to be worse on arduino builder than the old build system...

thanks for the warning :slight_smile: for some reason I am not keen on discovering new bugs of some minor IDE revision. unless of course the new IDE is really great (like a complete rewrite...)

would that new builder by any chance eliminate the braindead need to add all the lib includes into the main sketch - even if they are only used in some *.cpp sub-tab?

Not sure on that - but 1.6.6 and later (as I noted, 1.6.6~1.6.8 are buggy as hell) do have a completely rewritten build system (arduino-builder replaces the old build system). Much bigger changes than the changes from 1.6.3 to 1.6.5.

I think it's worth checking if the same behavior is present on versions using arduino-builder, as the change is large, and I know they fiddled with function prototype generation in arduino-builder.

In general, the Arduino team has been making a mockery of the concept of semantic versioning, it doesn't mean anything whether it's a major version or a minor one - they'll throw huge changes in if they feel like it, with no regard to backwards compatibility; As a maintainer of a third party hardware package, I've had to deal with like 4 breaking changes since 1.6.0 came out, and we've only had 10 minor versions....

DrAzzy:
I thought the automatic function prototype generation was said to be worse on arduino builder than the old build system...

I was recently trying to help someone with an issue they were having trying to modify a fairly complex sketch, LSOS(Light Saber Operating System). The author had gotten fed up with trying to maintain support for the Arduino IDE a while back and stated it could only be used in Eclipse. I didn't want to install Eclipse just to compile the sketch so gave it a try on Arduino IDE 1.6.9. It compiled fine without any changes. I mentioned that in the forum thread and there was such a positive response I thought I'd give it a try with older versions. With 1.6.5-r5 and previous there were quite a few different incorrectly generated prototypes that had to be manually declared to get it to compile. It was nice to find a case where arduino-builder provided an improvement over the old system after seeing it cause so much breakage. I've noticed the forum posts about problems caused by incorrect prototype generation with current IDE versions have really tapered off from the torrent that came following the release of 1.6.6.

I don't quite see the problem :wink: If automatic prototyping does not work, one can always write proper C / C++ and add the prototypes himself / herself. That should prevent any problems in future.

The only problem I see is that the IDE, in it's attempt to make it easier for newbies, creates sloppy programmers :frowning:

I find automatic prototype generation to be convenient. It's annoying to me to need to write essentially the same line of code twice and keep the two synchronized through edits. Not really that much work but this sort of repetitive, mindless work is what computers are supposed to do for me. So I do value this feature of the IDE even though I am quite capable of writing my own prototypes. The idea of making programming easier for beginners by simplifying the code writing process is a good one but when automatic prototype generation does fail it causes a lot of confusion and frustration. Luckily failures are rare with the sort of functions most beginners are writing. Arduino isn't necessarily intended to create professional programmers. It allows beginners to get to the "fun" part very quickly. Hopefully getting that LED blinking and that motor turning right away will get them hooked enough to want to go back and learn the "boring" stuff.

I agree it's probably best practice to write prototypes for example sketches that are released publicly even when the current Arduino IDE version correctly generates the prototypes. More complex example code without prototypes was what caused the most problems after the release of arduino-builder. Often this stuff gets abandoned by the author after a while, making it impossible to get the code fixed.

I just started playing with ESP8266 and have been using enums more(I don't use them with the Arduino AVR Boards core due to the extra overhead vs. byte) and I always need to write the prototypes. I tried adding enum as suggested by johnwasser but it didn't work for me.