Trouble with tempates

I am using Ubuntu 10.04LTS and have installed the Arduino software using the instructions in the Playground. This installs version 0018 which is working beautifully - with one exception.

I tried to compile the EEPROM_writeAnything code from the Playground and it refuses to compile with obscure error messages. Typically the cursor will go to an irrelevant line (such as one showing only a comment) and report <error: expected ‘,’ or ‘…’ before ‘&’ token>. I reduced the code down to the template declarations and it is clearly these which are causing the problem.

Other people are using this code successfully so I assume that the problem lies with my out of date version of the IDE.

Is this correct?
If so, how can I install the latest version on Ubuntu? Are there any instructions out there? I’m competent with Linux but emphatically no guru.

I’d be grateful for any pointers or comments.

I've compiled sketches using the EEPROM_readAnything and EEPROM_writeAnything templates on 0017, 0018, and 0019, with no issues.

Post the code that YOU are using, so we can see if you inadvertently omitted something.

Here is the code. I must confess that I’m not too hot on templates, but I cut and pasted that part of the code from the Playground.

#include <EEPROM.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;
}


struct config_t
  {
  long alarm;
  int nCount ;
  } configuration;

void setup()
  {
  configuration.nCount = 0 ;
  configuration.alarm = 0L ;
  EEPROM_writeAnything(0, configuration);
  }

void loop()
  {
  delay(1000) ;
  }

The error is <error: expected ‘,’ or ‘…’ before ‘&’ token> and the IDE doesn’t highight any line.

I’d be very grateful for your comments.

Regards, Pete

Unfortunately, this code snippet is not going to help us solve your problem. I know what the playground page has on it, and when I cut and paste that code into my sketch, I have no problems compiling.

Therefore, the difference must lie in WHERE in your sketch you are pasting that code vs. where in my sketch I paste the code.

So, we need to know WHERE in YOUR sketch you pasted that code.

I reduced my sketch down to that snippet in an attempt to isolate the fault. That struck me as pretty much the minimum code which would run and exercise the template - yet even that won't compile.

Does this minimal sketch compile on your system?

Regards, Pete

I missed seeing the scroll bars on you code. I didn't realize there was more code below it. But, yes, I copied that code, and pasted it into an Arduino 0019 window, on Win 7 64 bit, and it compiled fine.

Oh dear, so it must be an issue with the Linux cross compiler. Thanks for checking it out anyway.

Regards, Pete

Just for the record I updated my Linux software to version 0021 and the code compiles fine.

I think that the best advice for Ubuntu users new to Arduino is to follow the generic Linux installation instructions rather than installing the Ubuntu package which is now rather out of date. I’ve encountered several issues all of which were resolved by installing the latest release.

Pete