10. Endian Conversion
GM receive events are delivered to the user in network byte order. This
enhances the performance of GM programs, but is a minor inconveniece to
developers using the GM API. The client must call a special function to
convert each field read from the gm_recv_event_t
union to host
byte order. Neglecting this conversion will result in undefined
program behaviour in most cases.
In the absense of automatic checks, endian conversion is typically an
error-prone programming task. Therefore, support has been added to
GM-1.4 `gm.h' to ensure that no conversion is missing. Note,
however, the support is incompatible with the deprecated
gm_send()
/GM_SENT_EVENT
mechanism in GM.
All you need to do to activate the checking is add the line
| #define GM_STRONG_TYPES 1
|
before your the line
in your source code to activate this feature(2). Once
the feature is activated, the compiler will report errors if any type
conversion is missing. The error messages can be a bit cryptic and are
platform specific, but they generally indicate some sort of type
mismatch.
Endian conversion of fields in receive events from network to host order
is achieved with the following functions:
gm_ntohc()
- converts 8-bit fields
gm_ntohs()
- converts 16-bit fields
gm_ntohc()
- converts 32-bit fields
gm_ntohp()
- converts pointer-sized fields
These 4 functions should be sufficient to convert all the types you will
encounter in gm receive events.
This document was generated
by Glenn Brown on October, 18 2001
using texi2html