Big endian or little endian? I need to pass a 16-bit long address (for an external EEPROM) to a function (twi_writeTo) in a buffer.
I am currently doing this

byte buffer[2];
buffer[0] = (byte)(eeaddress &gt;&gt; 8);
buffer[1] = (byte)(eeaddress &amp; 0xFF);


where eeaddress is an unsigned int with the address. 

I then do

int8_t ret = twi_writeTo(eeprom_i2c_addr, buffer, 2, 1);


Before I tried

int8_t ret = twi_writeTo(eeprom_i2c_addr, (uint8_t*)&amp;eeaddress, 2, 1);


but that returns garbage. Probably the byte order is swapped. Is that the case?
And if so, is there a better way than copying the two bytes to a buffer?
If it's the byte order that causes a problem that's likely compiler specific and I don't think one can change it. Even if it were possible, changing the global endianness might break libraries that depend on it, so you likely can't escape using a function to swap the variable. 

If you know you only need one value at a time you could write something like the following code, with a global buffer (untested but in principle should work (and I know global variables are evil, but should work for an Arduino project)):

byte buf[2];

byte* reverse(int val) {
    buf[0] = (byte)(val &gt;&gt; 8);
    but[1] = (byte)val;
    return buf;
}


So you could use it like:

int8_t ret = twi_writeTo(eeprom_i2c_addr, reverse(eeaddress), 2, 1);