byte - BUG

...to reproduce the bug (in V1.0.5) do the following:

  1. Start a new sketch
  2. type: #include "test.h"
  3. add a tab and name it "test.h"
  4. type in "test.h": byte x;
  5. save and compile
    then the following error will appear: "test.h:1: error: 'byte' does not name a type"!

The generated code out of the pre-processing is:

#line 1 "sketch_jul24c.ino"
#include "test.h"

#include "Arduino.h"
void setup ();
void loop ();
#line 3
void setup ()
  {
  }  // end of setup

void loop () { }

The work-around is to put:

#include "Arduino.h"

... at the start of test.h.

I'm not sure if this is a bug or not. Another work-around is to make the main sketch read:

#include "Arduino.h"
#include "test.h"

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

Logically this makes sense, as the byte type is declared in Arduino.h (or something it includes). Thus normally when writing in C you would need to include it.

The pre-processor could conceivable put the automated include of "Arduino.h" further up the sketch. There is possibly/probably a reason why they don't.

I've raised a bug report:

However I should point out that if you wrote a separate .cpp file then the include for "Arduino.h" would be needed. For example if test.cpp includes test.h then there is not automatic addition of include directives to stand-alone compilation units (such as test.cpp or test.h).

...thanks a lot!

If anything, this really shows how Arduino's support for .cpp and .h files as tabs in the editor isn't well known or documented.