What's the easiest way of making the Wire library backwards compatible?

I'm trying to update some examples that use the old Wire (I2C) library. Unfortunately because of the way functions have been renamed it is hard to do it cleanly.

For example:

    Wire.beginTransmission (SLAVE_ADDRESS);
    Wire.send (x);
    Wire.endTransmission ();

Has to be changed to:

    Wire.beginTransmission (SLAVE_ADDRESS);
    Wire.write (x);
    Wire.endTransmission ();

But for people wanting to use the old 0022 IDE that won't work. So this perhaps:

    Wire.beginTransmission (SLAVE_ADDRESS);
#if defined(ARDUINO) && ARDUINO >= 100
    Wire.write (x);
#else
    Wire.send (x);
#endif
    Wire.endTransmission ();

But that looks really clunky if you have lots of reads/writes throughout the code. It obscures what you are trying to show.

I tried this but it doesn't compile:

#if !(defined(ARDUINO) && ARDUINO >= 100)
  #define Wire.write(x) Wire.send(x)
  #define Wire.read(x) Write.receive(x)
#endif

Error:

sketch_feb15a.cpp: In function 'void setup()':
sketch_feb15a:15: error: expected primary-expression before '.' token
sketch_feb15a:15: error: 'x' was not declared in this scope
sketch_feb15a:15: error: expected `;' before 'Write'

So far I used a "glue" function that compiles, but looks kinda weird:

// glue routines for version 1.0+ of the IDE
uint8_t i2c_read ()
  {
#if defined(ARDUINO) && ARDUINO >= 100
  return Wire.read ();
#else
  return Wire.receive ();
#endif
  } // end of i2c_read
  
void i2c_write (int data)
  {
#if defined(ARDUINO) && ARDUINO >= 100
  Wire.write (data);
#else
  Wire.send (data);
#endif
  } // end of i2c_write

Now I can write:

  Wire.beginTransmission (SLAVE_ADDRESS);
  i2c_write(x); 
  Wire.endTransmission();

But it still is a bit clunky. Is there a neater way?

But it still is a bit clunky. Is there a neater way?

Other that the name, I disagree. I think that if the function names were Wire_read and Wire_write, or something along those lines, that the code looks quite clean. You could hide those functions away in a separate file, and clean it up even more.

Don't forget the Wire.write (0); bug. That hit me on my first attempt to convert a V22 sketch to V1.0 which used the I2C library, even after I changed all the send/write and read/receive nonsense. It sounds like they have a patch for the new I2C library to eliminate that bug but who knows when the next release will be and if in fact it will include the fix?

Lefty