Go Down

Topic: byte - BUG (Read 4 times) previous topic - next topic

Joegi

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

Nick Gammon

The generated code out of the pre-processing is:

Code: [Select]

#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: [Select]

#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: [Select]

#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.
http://www.gammon.com.au/electronics

Nick Gammon

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

http://www.gammon.com.au/electronics

Joegi


Paul Stoffregen

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.

Go Up