error: 'EthernetClient' has not been declared

Hi folks,

I have a weird behaviour with the following test sketch:

byte mybyte; // if you move this line below the includes, it will compile

#include <SPI.h> 
#include <Ethernet.h>

void myfunction(byte mybyte, EthernetClient& curr_eth_client) {} // if you comment out this line, but leave the first line, byte mybyte, where it is, it will also compile

void setup() {}
void loop() {}

This sketch does not compile - error: 'EthernetClient' has not been declared

If I move the first line "byte mybyte;" BELOW the #include lines, it compiles.

OR

If I comment out the myfunction line, it also compiles.

I don't really understand what is going on. Am I violating rules by declaring a variable in the first line? But why does it compile fine then, if the myfunction is removed?

It doesn't matter if I use the Ethernet or the Ethernet2 library - same behaviour.

The includes seem to work even if the mybyte line is the first line. Evidence: If I remove the #include <spi.h>, I get an expected error message

C:\Program Files (x86)\Arduino\libraries\Ethernet\src/utility/w5100.h:13:17: fatal error: SPI.h: No such file or directory

Thank you for your help!

Which version of the Arduino IDE are you using? I can't reproduce the issue with 1.8.3.

I suspect it's a failure of the automatic prototype generation done during sketch preprocessing, which was more common with older IDE versions and especially 1.6.6 and those immediately following that version.

I am using Arduino IDE 1.6.3. I will download the current version and test it this evening.
Thanks for your answer.
Thomas

I tried it on the arduino web editor, and it compiles (verifies) fine. So it really seems to be a bug in the 1.6.3 version, which has been sorted out since.
Thank you for your help.

Where can I actually see which version the web editor is running? I only found the information

"(web-editor always has) the most up-to-date version of the IDE"

The current version of the IDE would be 1.8.3 at the moment.

Thomas

I'm glad to hear it's working for you now!

The IDE version doesn't really apply to the Arduino Web Editor because it's completely different. They do both use arduino-builder, which does the sketch preprocessing. Sometimes there are intermediate releases of arduino-builder between standard IDE releases so it's possible that the web editor will be using a newer version of arduino-builder than the standard IDE.