Yes, I see.
Well, using templates ...
sendAnything.h
#include <Arduino.h>
template <typename T> void sendAnything (const T& value)
{
const byte* p = (const byte*) &value;
for (unsigned int i = 0; i < sizeof value; i++)
Serial.write (*p++);
} // end of sendAnything
Sketch:
#include "sendAnything.h"
void setup ()
{
int MyInt;
sendAnything(MyInt);
} // end of setup
void loop () { } // end of loop
Size:
Binary sketch size: 1,404 bytes (of a 32,256 byte maximum)
Using pointers ...
Sketch:
void sendAnything(const byte *value, unsigned int size)
{
for (unsigned int i = 0; i < size; i++)
Serial.write(*value++);
}
void setup ()
{
int MyInt;
sendAnything((const byte *)&MyInt, sizeof(MyInt));
} // end of setup
void loop () { } // end of loop
Size:
Binary sketch size: 1,442 bytes (of a 32,256 byte maximum)
So the templated version used less program memory.
Even if I send two different type (int and float) the templated version still is 6 bytes shorter. Of course, if you were sending dozens of types of data (would you actually do that?) then the pointer version would use less program memory.
Test on a Uno with 1.0.1.