Joegi
July 24, 2013, 7:51pm
1
...to reproduce the bug (in V1.0.5) do the following:
Start a new sketch
type: #include "test.h"
add a tab and name it "test.h"
type in "test.h": byte x;
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:
opened 09:08PM - 24 Jul 13 UTC
closed 03:30PM - 11 Sep 15 UTC
Component: IDE
Component: Preprocessor
Example code ...
Sketch:
```
#include "test.h"
void setup () { }
void loop ()… { }
```
File "test.h":
```
byte x;
```
Error:
```
In file included from sketch_jul24c.ino:1:
test.h:1: error: 'byte' does not name a type
```
Generated code from pre-processor:
```
#line 1 "sketch_jul24c.ino"
#include "test.h"
#include "Arduino.h"
void setup ();
void loop ();
#line 3
void setup () { }
void loop () { }
```
If the include for "Arduino.h" had been done first (before the rest of the sketch was copied in) then the declarations in test.h would work. As it is, you now have to add an include into the front of all the .h files which defeats the usefulness of having the automatic inclusion in the main sketch.
IDE 1.0.5.
These look related:
https://github.com/arduino/Arduino/issues/1310
https://github.com/arduino/Arduino/issues/1328
https://github.com/arduino/Arduino/issues/1468
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).
pjrc
July 29, 2013, 1:16pm
5
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.