I'm trying to make a memory log of several variables in a flexible way. I need to pass a variable to a function, but only the position of first byte an the leg of this. I make this function, but not work...
unsigned int temp = analogRead(A0);
Registros.Concatenar(&temp, 2);
void Registro::Concatenar (char* Cadena, uint8_t Largo) {
for (uint8_t i = 0; Largo > i; i++) {
_RegistroAuxiliar[_RegistroOcupado] = Cadena[i];
_RegistroOcupado++;
}
}
But I have this error:
note: no known conversion for argument 1 from ‘unsigned int*’ to ‘char*’
...I need the memory position (pointer) of the first byte is the same if I have a Int or a long...
Wrong. A pointer is a data type that can point to a specific type of data (int, char, float). The rvalue of a pointer is the lvalue of the data item being pointed to. Those are not the same thing. The statement:
a = b;
takes the rvalue of b and places it in the rvalue of a. However, with a pointer:
ptr = &a;
takes the memory address of a (i.e., its lvalue) and assigns it into the rvalue of ptr. A valid pointer can only hold one of two values: 1) the lvalue of a variable of a specific data type, or 2) null. When you define ptr, you must tie it to some type of data, even if it is void.
econjack:
A valid pointer can only hold one of two values: 1) the lvalue of a variable of a specific data type, or 2) null.
I don't think that's quite accurate. What it means for a pointer to be 'valid' is open for debate, but if you mean that the pointer can be safely dereferenced then arguably null is not a valid value (unless you are actually accessing data at address zero), but the pointer is valid if it holds the address of any memory location where the pointed-to type can be accessed - it doesn't need to be the address of a variable. For example, if you are storing data in heap memory then it would be normal to use pointers to access that but there would be no corresponding variables at those locations.