对基本类型的再包装,方便了移植

对基本类型的再包装,方便了移植

   几乎每个像样的库,都会有自己定义的类型系统,如U8,U16等等,下面是摘选自resiprocate-1.4\rutil\stun\Stun.hxx的,
   

#ifndef RESIP_COMPAT_HXX
//  define some basic types
typedef unsigned  char   UInt8;
typedef unsigned 
short  UInt16;
#ifdef __APPLE__
typedef unsigned 
long    UInt32;
#else
typedef unsigned 
int    UInt32;
#endif
#if  defined( WIN32 )
typedef unsigned __int64 UInt64;
#else
typedef unsigned 
long   long  UInt64;
#endif
#endif

typedef 
struct   { unsigned char octet[16]; }   UInt128;
   随着64位服务器的逐渐普及,int类型在32位和64位机下代表的字节数可能不再相同,这对现有的服务器的协议解析会造成一定麻烦,比如,协议解析时,可能有,
int nCmdType = (int)ptr;
ptr += 4;
   所以,自己在开发底层库时,封装一下基本类型,既提高了可读性,也易于移植

你可能感兴趣的:(对基本类型的再包装,方便了移植)