changing from long to bytes and vice versa I want to converse data from long to bytes and vice versa. After searching around, I sticked together some code, which seems to work (the same code works for int and floats as well).

The long value LongVal changes to a byte array, and the four bytes construct LongVal2. Obviously LongVal = LongVal2.  

long LongVal = -4080;
long LongVal2;

void setup(){
  Serial.begin(9600);
}

//byte* my_function(long LongVal){
//  byte *LongVal_byte = (byte *) &amp; LongVal; 
//  return &amp; (LongVal_byte[0]);
//}

//long my_function2(byte &amp; LongVal_byte){
//  long LongVal2;
//  memcpy(&amp;LongVal2, LongVal_byte, sizeof(LongVal2));
//  return  LongVal2;
//}

void loop(){

  byte *LongVal_byte = (byte *) &amp; LongVal; 
  memcpy(&amp;LongVal2, LongVal_byte, sizeof(LongVal2));
  Serial.println(LongVal2);  
  Serial.println(" ");  

//byte LongVal_byte = my_function(long LongVal);
//LongVal2 = my_function2(byte &amp; LongVal_byte);  

}


But should I try to wrap the two first lines of loop() in two individual functions, errors occur. The remarked lines are my attempts to create two functions.

How to wrap them up properly?

EDIT
This is what appears if I try to use the remarked functions:

 In function 'long int my_function2(byte&amp;)':
15:51: error: invalid conversion from 'byte {aka unsigned char}' to 'const void*' [-fpermissive]
25:0,
1:
117:14: error:   initializing argument 2 of 'void* memcpy(void*, const void*, size_t)' [-fpermissive]

 In function 'void loop()':
26:33: error: expected primary-expression before 'long'
27:30: error: expected primary-expression before '&amp;' token
So many problems here:

1) in function call there shouldn't be types, only arguments. byte LongVal_byte = my_function(LongVal);

2) &amp; before variable means "get variable address". However in function prototype long my_function2(byte &amp; LongVal_byte) it means reference to passed variable (and it must be byte), not a pointer.

3) pointer to local variable is returned from my_function. It might be working until pointed memory gets rewrited by something else (another function call or so)

And whole code might look like that:

long LongVal = -4080;
long LongVal2;

void setup(){
  Serial.begin(9600);
}

byte * my_function(long &amp; LongVal) {
  return (byte*)&amp;LongVal;
}

long my_function2(byte * LongVal_byte) {
  return *((long *)LongVal_byte);
}

void loop(){

  byte * LongVal_byte = my_function(LongVal);
  LongVal2 = my_function2(LongVal_byte);  

  Serial.println(LongVal2);  
  Serial.println(" "); 
}


But it is basically exactly the same as before without functions (just no need for memcpy)