Understanding arguments in avr/eeprom.h functions

I'm inclined to agree about the pointer. However generally when things "point" to data in memory you use a pointer. I suppose you could say the data in EEPROM is in memory, and thus a pointer is justified.

As for the const, it is because what the pointer is pointing to doesn't change.

I can never remember which way around they go, so here are some tests:


You can modify the pointer:

void setup ()
  {
  const char * p = "hello";
  p++;
  }  // end of setup

void loop () { }

But not what it points to:

void setup ()
  {
  const char * p = "hello";
  *p = 'a';
  }  // end of setup

void loop () { }

Error:

sketch_jan03a.cpp: In function 'void setup()':
sketch_jan03a:3: error: assignment of read-only location '* p'

Move the const and the opposite applies:

void setup ()
  {
  char * const p = "hello";
  p++;
  }  // end of setup

void loop () { }

Error:

sketch_jan03a.cpp: In function 'void setup()':
sketch_jan03a:3: error: increment of read-only variable 'p'

However this compiles OK:

void setup ()
  {
  char * const p = "hello";
  *p = 'a';
  }  // end of setup

void loop () { }

Two consts, and you can't change the pointer or what it points to:

void setup ()
  {
  const char * const p = "hello";
  *p = 'a';
  p++;
  }  // end of setup

void loop () { }
sketch_jan03a.cpp: In function 'void setup()':
sketch_jan03a:3: error: assignment of read-only location '*(const char*)"hello"'
sketch_jan03a:4: error: increment of read-only variable 'p'