Previous: Automatic Transfer Function Generation Up: Data Transfer Functions Next: Examples
Pitfalls
Here are some things about data transfer functions to watch out for:
- A default constructor must be defined for all types. The
default constructor is invoked before an object is unpacked using
operator>>.
- Although the compiler may be able to generate the correct
transfer functions for a type, where correct means an identical copy
of the object is produced in the remote processor objct, that may not be
what you want. You can generate the transfer functions for any type
you want; the compiler only generates functions for types you do not.
- The const in the argument to operator<< is
important! Modifying the structure while it is being packaged is
modifying a mutable variable while it is being read.
- Be careful when passing structures with global pointers. The
compiler-generated transfer functions will pass the global pointer,
not the object referenced by the global pointer. The Examples section
below explores this issue in more detail.
- It is good practice to think of operator<< and
operator>> as two more functions to be defined for each type, along
with the constructor, the destructor, the assignment operator, etc.