Pages: [1]   Go Down
Author Topic: byte - BUG  (Read 4033 times)
0 Members and 1 Guest are viewing this topic.
cologne, germany
Offline Offline
Jr. Member
**
Karma: 1
Posts: 65
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

...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"!
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The generated code out of the pre-processing is:

Code:
#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:

Code:
#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:

Code:
#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.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I've raised a bug report:

https://github.com/arduino/Arduino/issues/1518

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).

Logged

cologne, germany
Offline Offline
Jr. Member
**
Karma: 1
Posts: 65
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

...thanks a lot!
Logged

0
Offline Offline
God Member
*****
Karma: 25
Posts: 606
Always making something...
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: [1]   Go Up
Jump to: