Warning when saving memory address to variable?

Kuba0040

Well-known member
Hello,
I have a pretty simple piece of code. I want to store the memory address of TestChunkMemory into TestChunkAdress, as shown here:
Code:
int32_t TestChunkMemory[64];
uint32_t TestChunkAdress=&TestChunkMemory;

However, the compiler always gives me this warning:
warning: invalid conversion from 'int32_t* {aka long int*}' to 'uint32_t {aka long unsigned int}' [-fpermissive]

The code compiles and works just fine though, any ideas of how I can get rid of this warning? Also, are there other ways to store the memory address of a variable to then be able to access it quickly? Why not just use a pointer? -> I can't use a pointer here as I must be able to pass this memory address to functions. Using pointers like so causes it to change:
Code:
void test_function(int32_t *LocalPointer)
{
  Serial.print("Local adress: ");
  println64(&LocalPointer);
}

Thank You for the help.
 
Change the second line to:
Code:
int32_t *TestChunkAdress=&TestChunkMemory;
This declares TestChunkAddress to be a pointer to (address of) an int32_t.

Pete
 
any ideas of how I can get rid of this warning?

Probably like this.

Code:
int32_t TestChunkMemory[64];
uint32_t TestChunkAdress=(uint32_t)&TestChunkMemory[0];

void setup() {
  while (!Serial) ;
  Serial.print("Local adress: ");
  Serial.println(TestChunkAdress, HEX);
}

void loop() {
}
 
Using pointers like so causes it to change:
Code:
void test_function(int32_t *LocalPointer)
{
  Serial.print("Local adress: ");
  println64(&LocalPointer);
}

Yes, indeed. The variable "LocalPointer" is already the address you want to print. By using "&LocalPointer", you're telling the compiler to print the address where the address of your data is being stored.

This is the syntax you probably wanted.

Code:
void test_function(int32_t *LocalPointer) {
  Serial.print("Local adress: ");
  Serial.println((uint32_t)LocalPointer, HEX);
}
 
Back
Top