32.64

来源:互联网 发布:印象笔记mac画图 编辑:程序博客网 时间:2024/05/16 04:21

(a)     ACE函数类型

ACE函数的类型是什么,就使用什么的类型,不要很随意的使用其他类型。

不兼容代码

server\src\sm\NeLicense\NeLicenseUtils.cpp  

#ifdef SUSE_IA64

  ALM_HANDLE hWorkSpace= 0;

#else

  ALM_UINT32 hWorkSpace= 0;

#endif   

  iRet = AdaptiveLMStandAloneInit(pchBuf,

                                 ulSpaceSize,

                                 cFileBuff,

                                 ...

修改方法:

  ALM_HANDLE hWorkSpace= 0;

1      printf/scanf:用系统预定义宏做为格式字符串

不兼容代码

#ifdef SUSE_IA64

int value;

sprintf( buff, "%d", value);

sscanf( buff, "%d", value);

#else

long value;

sprintf( buff, "%ld", value);

sscanf( buff, "ld, value);

#endif

推荐修改方法:

#include <inttypes>

int32_t value;

sprintf( buff, PRIdFAST32, value);

sscanf( buff, SCNdFAST32, value);

 

 

更多的格式字符串,参考/usr/include/inttypes.h

/usr/include/inttypes.h:

# if __WORDSIZE == 64

define __PRI64_PREFIX        "l"

define __PRIPTR_PREFIX       "l"

# else

define __PRI64_PREFIX        "ll"

define __PRIPTR_PREFIX

# endif

 

# define PRIdFAST32    __PRIPTR_PREFIX "d"

 

2   常见数据类型长度对比

数据类型

32位的字节大小

64位的字节大小(LP64

char

1

1

short

2

2

int

4

4

long

4

8

long long

8

8

double

8

8

size_t

4

8

wchar_t

2

4

pointer

4

8

注:仅仅是指当前我们使用的LP64位平台。我们当前的IA64LP64.

3   CPU字节序问题

Little Endian

ATCAX86)、HPIntegrity

Big Endian

SUNSparc)、IBMpower

4   针对结构体的特别解释

On most systems, the compilers align data types on a natural boundary. This means that 32-bit data types are aligned on a 32-bit boundary and 64-bit data types are aligned on a 64-bit boundary on 64-bit systems. In a data structure, this means that a filler (or padding) could be inserted by the compiler to enforce this alignment. The structure itself is also aligned based on its widest member. Thus, on a 64-bit system, a struct or union itself may be aligned on a 64-bit boundary. The following structure and table illustrates how this alignment may be applied by the compiler:

struct align {

int a;

double b;

int c;

long d;

};

On a 32-bit system, the compiler may not align the variable b on a 64-bit boundary (even though it is a 64-bit object) because the hardware treats it as two 32-bit objects. A 64-bit system aligns both b and d on 64-bit boundaries, causing two 4-byte fillers (or padding) to be added.

 

5   Standard type definitions

There are some type definitions that are of special interest to the developer, as their use enhances the portability of the code:

 

6   不同操作系统、数据库的编译宏定义

我们目前会存在的发货平台:

1SUN + UNIX (Solaris) + SYBASE + M200032位)

2SUN + UNIX (Solaris) + ORACLE + M200032位)

3HP + LINUX (SUSE) + ORACLE + M200064位)

4ATAEPC Server + LINUX (SUSE) + ORACLE + M200032位)

 

我们的代码是一套,在不同的平台上面单独编译出版本。针对不兼容的地方定义宏如下:

编译宏变量定义如下

编译过程中,需要动态的判定当前的操作系统和数据库的类型,编译使用的宏变量

C++相关的编译宏:

SUN                   ------------sparcCPU的Solaris(SUN)

SUSE_X86             -------------x86 CPU的SuSE Linux(ATAE、PC)

SUSE_IA64            -------------IA64 CPU的SuSE Linux(HP小型机)

SUSE_POWER          --------------Power CPU的SuSE Linux(IBM小型机)

 

数据库相关的编译宏:

ORACLE               -------------------Oracle数据库

SYBASE               -------------------Sybase数据库

DB2                  -------------------DB2数据库

MYSQL                -------------------mySQL数据库

 

举例如下

#ifdef SUSE_IA64

...

#else

   ..

#endif

 

 

运行宏变量定义如下

运行过程中,需要动态的判定当前的操作系统和数据库的类型,请直接读取对应的变量:

操作系统的变量OMC_OS_TYPE, 其中的值分别为:

SUN                   ------------sparcCPU的Solaris(SUN)

SUSE_X86             -------------x86 CPU的SuSE Linux(ATAE、PC)

SUSE_IA64            -------------IA64 CPU的SuSE Linux(HP小型机)

SUSE_POWER          --------------Power CPU的SuSE Linux(IBM小型机)

 

数据库的变量OMC_DB_TYPE,其中的值分别为:

ORACLE               -------------------Oracle数据库

SYBASE               -------------------Sybase数据库

DB2                  -------------------DB2数据库

MYSQL                -------------------mySQL数据库

 

 

举例如下

if [ "$OMC_DB_TYPE" = "DB2" ]; then

....

else

    ...

fi

0 0