Windows(R) 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

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);
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, "%ld", &SBCSprt);

%ld tries to put an eight byte type into a four 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 WebSphere MQ platforms: