eeprom native library

Hello
Today I was using the eeprom using the native library of avrlibc #include <avr/eeprom.h>
The function in documentation is:

uint8_t eeprom_read_byte 	( 	const uint8_t *  	__p	) 	
Read one byte from EEPROM address __p.

it return a byte and needs as argument a pointer to an adress
So far so good, my problem starts now when I use the function passing the address of the position.

int adress = 0;//I want position 0
int readValue = eeprom_read_byte(&i);//It wount work as expected don´t understand why
int readValue = eeprom_read_byte((uint8_t *)i);//Doing a cast work's well but why ?

The eeprom_read_byte() function expects an address. You defined one. But, what the heck is i?

You are reading a byte, and storing it in an int. Why?

Sorry my mistake typing Here is the correct one:

uint8_t adress = 0;//I want position 0
uint8_t readValue = eeprom_read_byte(&adress);//It wount work as expected don´t understand why
uint8_t readValue = eeprom_read_byte((uint8_t *)adress);//Doing a cast work's well but why ?

So you want the byte at address 0 in eeprom? Then take the ampersand off. With the ampersand you are giving it the address of the variable adress and that isn't 0.

I may have had a similar question recently, see it this thread is of any help: http://arduino.cc/forum/index.php/topic,140376.msg1054626.html

With the ampersand you are giving it the address of the variable adress and that isn't 0.

But the function expect an address!! I cannot pass the variable

But the function expect an address!!

But not the address of the variable that holds the address. Making that function take a pointer was probably not the brightest move. But, you know how to pass it what it wants, so quit worrying about why that works. Just accept that it does.

But not the address of the variable that holds the address

Uhmm I was thinking that passing the address of the variable was in fact making the functions "looks" to the value 0 which was the eeprom address I want. Perhaps you are right, time to move on and just use the cast.

HugoPT:

But not the address of the variable that holds the address

Uhmm I was thinking that passing the address of the variable was in fact making the functions "looks" to the value 0 which was the eeprom address I want. Perhaps you are right, time to move on and just use the cast.

That's it. With the ampersand you were passing it an address in SRAM where the variable adress lives. If adress was at say address 32 in SRAM, then you were passing the 32 and not the 0 to the function.