Hrm... thanks Paul. Tried your suggestion, i still cannot compile, same errors. I am on Linux (Centos 5)...
It has nothing to do with Linux. I am using avr-gcc version 4.3.4 compiled from source on Centos 5.5 Linux. (Also tested on Arduino 0022 distribution on Windows XP.)
Here's the deal:
Between arduino-0021 and arduino-0022, the order in which function prototypes appear in the C++ file that Arduino generates from your sketch has changed. See Footnote.
Among other things that used to work but don't work now, it turns out that -0022 requires that template definitions be placed in a separate header file. (That's the way that I usually organize C++ projects anyhow, so I wouldn't have noticed the difference if this problem hadn't been reported), but it would be nice if someone would spell it out on the Arduino EEPROM library page for this stuff.)
Anyhow, try the following:
Open a tab and name it "Anything.h" (or some such thing).
Take all of the template stuff out of the main sketch and put it there. You have to include <EEPROM.h> to get EEPROM stuff defined, and you have to include <WProgram.h> to get various Arduino types defined.
Here's what goes in the header tab:
// Header file "Anything.h" to allow EEPROM_writeAnything and
// EEPROM_readAnything examples to compile under arduino-0022
//
// Due to the (broken) way that Arduino version 0022 collects function
// prototypes before other things in the main sketch, template
// stuff must be in a separate header
//
// davekw7x
//
#include <EEPROM.h>
#include <WProgram.h>
template <class T> int EEPROM_writeAnything(int ee, const T& value)
{
const byte* p = (const byte*)(const void*)&value;
int i;
for (i = 0; i < sizeof(value); i++)
EEPROM.write(ee++, *p++);
return i;
}
template <class T> int EEPROM_readAnything(int ee, T& value)
{
byte* p = (byte*)(void*)&value;
int i;
for (i = 0; i < sizeof(value); i++)
*p++ = EEPROM.read(ee++);
return i;
}
The main sketch now looks like the following:
#include <EEPROM.h>
#include "Anything.h"
//
// Template stuff removed and placed in separate header file
// davekw7x
struct config_t
{
long alarm;
int mode;
} configuration;
void setup()
{
EEPROM_readAnything(0, configuration);
// ...
}
void loop()
{
// let the user adjust their alarm settings
// let the user adjust their mode settings
// ...
// if they push the "Save" button, save their configuration
if (digitalRead(13) == HIGH)
EEPROM_writeAnything(0, configuration);
}
Regards,
Dave
Footnote:If you want to see what the compiler is actually presented with, after Arduino massages your sketch file(s), hold a "Shift" key down when you click the "verify" button. It tells you the name of the temporary directory that will hold the generated C++ file. Look at it when you have everything in the main sketch (no separate header). Now look at the cpp file that is generated when you include the template definitions in a separate header.
If you are really interested (and if you are still awake), you can compare the way that arduino-0021 did it with the way that arduino-0022 does it. And you can try to remember this in case you are ever in the position of "improving" a previous version of some system of programs. There is always a reason that people do things and change things. It may even be a "good" reason, but you always have to be ready to fix "unindented consequences." Or at least document them.