Include errors

Hello folks,

i have been running into a strange problem i don´t understand.
For a network based project i wrote 3 different sketches which share a common logic for data exchange. When i tried to organize my code into seperate filed i ran into some errors which i cant explain because on 1 of the 3 sketches i can compile without errors and the rest complains if there was no function on top of my file. After some testing i narrowed down the problem:

main file

#include "struct.h"
#include <WSWire.h>


void setup() {

}

void loop() {

}
#ifndef struct_h
#define struct_h


#define EEPROM_ID 1
struct EEPROM
{
  byte pas_magnets;
  byte wheel_magnets;
  unsigned int circumference;
  unsigned long milage;
  unsigned int throt_in_min;
  unsigned int throt_in_max;
  unsigned int throt_out_min;
  unsigned int throt_out_max;
  unsigned int voltage_divider;
  unsigned int shunt;
  byte throt_out_low[16];
  byte throt_out_high[16];
};

#define DRIVE_ID 2
struct DRIVE
{
  unsigned int pas_rpm;
  unsigned int wheel_tacho;
  unsigned int motor_tacho;
  unsigned long wheel_rotations;
  unsigned int bat_volt;
  unsigned int bat_current;
};

#define BMS_ID 3
struct BMS
{
  unsigned int cells[13];
  unsigned int bms_total_voltage;
  unsigned int current;  
  unsigned int rsense;
  byte cellreference;  //1.22 for cell type 0/1, for 2/3 0.61
  byte cellcount;
  boolean bms_mode;
};

#define LCD_REQ_ID 4
struct LCD_REQ
{
unsigned int cruise_speed;
byte drive_mode;
};

#define OK_ID 5
struct OK
{
boolean state;
};

#endif

The begin of the working sketch

#include "U8glib.h"
#include "templates.h"
#include <SPI.h>

//i2c
#include <WSWire.h>
#include "struct.h"

When i put

#include <SPI.h>

on top of my testsketch it compiles without errors, else i get:

In file included from fail.ino:1:
struct.h:8: error: 'byte' does not name a type
struct.h:9: error: 'byte' does not name a type
struct.h:18: error: 'byte' does not name a type
struct.h:19: error: 'byte' does not name a type
struct.h:40: error: 'byte' does not name a type
struct.h:41: error: 'byte' does not name a type
struct.h:42: error: 'boolean' does not name a type
struct.h:49: error: 'byte' does not name a type
struct.h:55: error: 'boolean' does not name a type

Can anybody explain this to me ? (Using 1.05)

Thanks in advance

Can anybody explain this to me ?

What is to explain? The "types" byte and boolean are defined in Arduino.h, which your header file does not include. It should.

Ok i understand, but why is it working when i include the <SPI.h> ?

smithy:
Ok i understand, but why is it working when i include the <SPI.h> ?

This is a perfect opportunity for you to look at SPI.h and see what it actually does.

I just did:

#ifndef _SPI_H_INCLUDED
#define _SPI_H_INCLUDED

#include <stdio.h>
#include <Arduino.h>
#include <avr/pgmspace.h>

But that iss missleading, because of following information:

Transformations to the main sketch file

The Arduino environment performs a few transformations to your main sketch file (the concatenation of all the tabs in the sketch without extensions) before passing it to the avr-gcc compiler.

First, #include “Arduino.h”, or for versions less than 1.0, #include “WProgram.h” is added to the top of your sketch. This header file (found in /hardware/cores//) includes all the defintions needed for the standard Arduino core.

But that iss missleading, because of following information:

You took that a bit too literally.

The Arduino environment performs a few transformations to your main sketch file (the concatenation of all the tabs in the sketch without extensions) before passing it to the avr-gcc compiler.

First, #include "Arduino.h", or for versions less than 1.0, #include "WProgram.h" is added to the top of your sketch.

That should say "is added to somewhere vaguely near the top...".

Exactly where matters. It is probably being included AFTER your file.

With SPI.h included, it gets included before your file.

Yeah maybe i did, thank you very much for answering this in detail.