Main Page   Modules   Data Structures   File List   Data Fields   Globals   Related Pages  

X. 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 inconvenience 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 behavior in most cases.

In the absence 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 the line
     \#include "gm.h"
in your source code. 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:

Network to host conversion routines.

gm_ntoh_u8() unsigned 8-bit

gm_ntoh_u16() unsigned 16-bit

gm_ntoh_u32() unsigned 32-bit

gm_ntoh_u64() unsigned 64-bit

gm_ntoh_s8() signed 8-bit

gm_ntoh_s16() signed 16-bit

gm_ntoh_s32() signed 32-bit

gm_ntoh_s64() signed 64-bit

Host to network conversion routines.

gm_hton_u8() unsigned 8-bit

gm_hton_u16() unsigned 16-bit

gm_hton_u32() unsigned 32-bit

gm_hton_u64() unsigned 64-bit

gm_hton_s8() signed 8-bit

gm_hton_s16() signed 16-bit

gm_hton_s32() signed 32-bit

gm_hton_s64() signed 64-bit

(1) On 64-bit Solaris machines, the GM_STRONG_TYPES feature can be used during compilation to check for missing conversion, but it the resulting programs will not run and must be recompiled without this feature.


Generated on Mon Nov 3 15:39:27 2003 for GM by doxygen1.2.15