Address calculations with MI_DATUM values
In performing address calculations with datums, do not use char * as the type. This practice can lead to problems. Instead, calculate addresses with the size_t data type.
To increment a datum by an arbitrary length, use the following
equation:
void *ptr = (void *)((size_t)datum + (size_t)length )
In performing address calculations with an MI_DATUM value, it is common practice to use char * as an intermediate type because arithmetic operators are not allowed on the void * type. The ANSI C standard explicitly says that void * and char * have the same representation.
For example, the following code increments an MI_DATUM value
by an arbitrary length:
MI_DATUM ptr = (MI_DATUM) ((char *)(datum) + (ptrdiff_t)(length))
In the preceding formula, ptrdiff_t is defined in the ANSI C header file, stddef.h, and is a signed integer data type.
Another addressing scheme follows:
void *ptr = ((char *)datum) + length