samedi 2 janvier 2016

How to format "if" statement in C++ macro

I need some help formatting my "if" statement in this C++ macro please:

#define updateEEPROMVal(address,val)  if (EEPROM.get(address)!=val) \
                                        EEPROM.put(address,val)

I'm getting pages of errors, so I'm assuming it's a simple formatting problem.

Here's the full context:

//----------------------------------------------------------------------------------------------------------------------------------
//storeXYValsIntoEEPROM
//-store the current global variable x and y low, center, and high values into EEPROM
//----------------------------------------------------------------------------------------------------------------------------------
#define updateEEPROMVal(address,val)  if (EEPROM.get(address)!=val) \
                                        EEPROM.put(address,val)
void storeXYValsIntoEEPROM()
{
  //update EEPROM values *only* if necessary, this way you minimize writes (and wear-and-tear) on the EEPROM, since it is limited to
  //100k writes per cell I believe (see datasheet)
  updateEEPROMVal(0,x_low);
  updateEEPROMVal(2,x_ctr);
  updateEEPROMVal(4,x_high);
  updateEEPROMVal(6,y_low);
  updateEEPROMVal(8,y_ctr);
  updateEEPROMVal(10,y_high);
}

Aucun commentaire:

Enregistrer un commentaire