"error: 'byte' has not been declared" when in header, not elsewhere

Here’s the code all in one file:

#include <Wire.h>
#include "i2c.h"

int read_register(int device_address, byte reg_address);

void write_register(int device_address, byte reg_address, byte data);

void setup()
{
}

void loop()
{
  read_register(3,2);
  write_register(4,3,2);
}

int read_register(int device_address, byte reg_address)
{
	int v;
    Wire.beginTransmission(device_address);
    Wire.write(reg_address);				// register to read
    Wire.endTransmission();
    Wire.requestFrom(device_address, 1);		// read a byte
    while(!Wire.available()) {
			// waiting
    }
    v = Wire.read();
    return v;
}

void write_register(int device_address, byte reg_address, byte data){
    Wire.beginTransmission(device_address); // Select device
    Wire.write(reg_address);                   // Select register
    Wire.write(data);                      // Write to register
    Wire.endTransmission();
}

However, when I move the read_register and write_register declarations to the i2c.h file called at the beginning, I get “‘byte’ has not been declared” compiler error. My intent is to move all the i2c functions to another file, but the byte error makes me worry that I am doing something wrong. I put #include <Wire.h> all over without success.

I’m on windows 8.1 and an arduino Uno. It has been a very long while since I programmed!

Thanks in advance!

However, when I move the read_register and write_register declarations to the i2c.h file called at the beginning, I get "'byte' has not been declared" compiler error.

Why do you think it is defined in the i2c.h file?

Where do you think byte is defined? It is not a native C type.

Have a look at Arduino.h. Considering including it in your header file.

You can take the advice PaulS offered, or use uint8_t instead of byte.

Thanks a bunch! I was wondering where byte was defined, the fact that it only sometimes gave me errors was messing me up.

Yall are great.

SurferTim:
You can take the advice PaulS offered, or use uint8_t instead of byte.

If inside a library, you will either have to include Arduino.h, or stdint.h to use the aliases like uint8_t.

pYro_65:

SurferTim:
You can take the advice PaulS offered, or use uint8_t instead of byte.

If inside a library, you will either have to include Arduino.h, or stdint.h to use the aliases like uint8_t.

That has not been my experience, but i could be wrong. One of those could have been included in an included file.

edit: Arduino.h has the byte data type as an alias for uint8_t. If the OP had included that file, then byte would have been declared.