[UNIX, Linux, Windows]

Standard data types on UNIX, Linux, and Windows

Learn about standard data types on 32-bit UNIX and Linux®, 64-bit UNIX and Linux, and 64-bit Windows applications.

[UNIX][Linux]

32-bit UNIX and Linux applications

This section is included for comparison and is based on Solaris. Any differences with other UNIX platforms are noted:
Name Length
char 1 byte
short 2 bytes
int 4 bytes
long 4 bytes
float 4 bytes
double 8 bytes
long double 16 bytes

[AIX][Linux]Note that on AIX® and Linux PPC a long double is 8 bytes.

pointer 4 bytes
ptrdiff_t 4 bytes
size_t 4 bytes
time_t 4 bytes
clock_t 4 bytes
wchar_t 4 bytes

[AIX]Note that on AIX a wchar_t is 2 bytes.

[UNIX][Linux]

64-bit UNIX and Linux applications

This section is based on Solaris. Any differences with other UNIX platforms are noted:
Name Length
char 1 byte
short 2 bytes
int 4 bytes
long 8 bytes
float 4 bytes
double 8 bytes
long double 16 bytes

[AIX][Linux]Note that on AIX and Linux PPC a long double is 8 bytes.

pointer 8 bytes
ptrdiff_t 8 bytes
size_t 8 bytes
time_t 8 bytes
clock_t 8 bytes

Note that on the other UNIX platform a clock_t is 4 bytes.

wchar_t 4 bytes

[AIX]Note that on AIX a wchar_t is 2 bytes.

[Windows]

Windows 64-bit applications

Name Length
char 1 byte
short 2 bytes
int 4 bytes
long 4 bytes
float 4 bytes
double 8 bytes
long double 8 bytes
pointer 8 bytes

Note that all pointers are 8 bytes.

ptrdiff_t 8 bytes
size_t 8 bytes
time_t 8 bytes
clock_t 4 bytes
wchar_t 2 bytes
WORD 2 bytes
DWORD 4 bytes
HANDLE 8 bytes
HFILE 4 bytes
[Windows]

Coding considerations on Windows

HANDLE hf;
Use

hf = CreateFile((LPCTSTR) FileName,
                Access,
                ShareMode,
                xihSecAttsNTRestrict,
                Create,
                AttrAndFlags,
                NULL);
Do not use

HFILE hf;
hf = (HFILE) CreateFile((LPCTSTR) FileName,
                        Access,
                        ShareMode,
                        xihSecAttsNTRestrict,
                        Create,
                        AttrAndFlags,
                        NULL);
as this produces an error.
size_t len fgets
Use

size_t len
while (fgets(string1, (int) len, fp) != NULL)
len = strlen(buffer);
Do not use

int len;

while (fgets(string1, len, fp) != NULL)
len = strlen(buffer);
printf
Use

printf("My struc pointer: %p", pMyStruc);
Do not use

printf("My struc pointer: %x", pMyStruc);
If you need hexadecimal output, you have to print the upper and lower 4 bytes separately.
char *ptr
Use

char * ptr1;
char * ptr2;
size_t bufLen;

bufLen = ptr2 - ptr1;
Do not use

char *ptr1;
char *ptr2;
UINT32 bufLen;

bufLen = ptr2 - ptr1;
alignBytes
Use

alignBytes = (unsigned short) ((size_t) address % 16);
Do not use

void *address;
unsigned short alignBytes;

alignBytes = (unsigned short) ((UINT32) address % 16);
len
Use

len = (UINT32) ((char *) address2 - (char *) address1);
Do not use

void *address1;
void *address2;
UINT32 len;

len = (UINT32) ((char *) address2 - (char *) address1);
sscanf
Use

MQLONG SBCSprt;

sscanf(line, "%d", &SBCSprt);
Do not use

MQLONG SBCSprt;

sscanf(line, "%1d", &SBCSprt);

%ld tries to put an 8-byte type into a 4-byte type; only use %l if you are dealing with an actual long data type. MQLONG, UINT32 and INT32 are defined to be four bytes, the same as an int on all IBM® MQ platforms: