Accessing int as bytes

I want to use a byte array to easily store and retrieve data from EEPROM. However some of the data elements need to be ints(16 bits).
Previously using a C compiler for the PIC I've used this:

int EEparams[6];

#byte Iset=EEparams
#byte Ontime=EEparams+1
#byte Offtime=EEparams+2
#long Vtrip=EEparams+3
#byte EEflags=EEparams+5

( appears confusing because on this compiler 'int' is an 8 bit variable

This allows the long (which is 2 bytes in length) to be directly accessed as a 16 bit variable (Vtrip), it also allows each byte to be read and written to separately (EEparams[3] and EEparams[4].

Is there an equivalent to this for the Arduino language?

Thanks for any help :slight_smile:

#byte is not standard C preprocessor.

Use a pointer, or check out the EEPROM library

I think the equivalent would be to get a byte pointer to point at your int. That will require a cast.

The easier way might be to use the Arduino functions highByte and lowByte. They'll work as long as everything is int and not long.

Additionally, there's the EEPROM library which can handle all of that for you.

Thanks for the replies.

Is there a guide to pointers anywhere?
Re highByte and lowByte, is there a reciprocal function that allows writing a byte value to the high and low bytes of an int?

Is there a guide to pointers anywhere?

Any C/C++ tutorial.

NevilleC:
Re highByte and lowByte, is there a reciprocal function that allows writing a byte value to the high and low bytes of an int?

word()