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]](ngunix.gif)
![[Linux]](nglinux.gif)
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
|
| pointer | 4 bytes |
| ptrdiff_t | 4 bytes |
| size_t | 4 bytes |
| time_t | 4 bytes |
| clock_t | 4 bytes |
| wchar_t | 4 bytes
|
![[UNIX]](ngunix.gif)
![[Linux]](nglinux.gif)
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
|
| 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
|
![[Windows]](ngwin.gif)
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]](ngwin.gif)
Coding considerations on Windows
- HANDLE hf;
-
Use
Do not usehf = CreateFile((LPCTSTR) FileName, Access, ShareMode, xihSecAttsNTRestrict, Create, AttrAndFlags, NULL);
as this produces an error.HFILE hf; hf = (HFILE) CreateFile((LPCTSTR) FileName, Access, ShareMode, xihSecAttsNTRestrict, Create, AttrAndFlags, NULL); - size_t len fgets
-
Use
Do not usesize_t len while (fgets(string1, (int) len, fp) != NULL) len = strlen(buffer);int len; while (fgets(string1, len, fp) != NULL) len = strlen(buffer); - printf
-
Use
Do not useprintf("My struc pointer: %p", pMyStruc);
If you need hexadecimal output, you have to print the upper and lower 4 bytes separately.printf("My struc pointer: %x", pMyStruc); - char *ptr
-
Use
Do not usechar * ptr1; char * ptr2; size_t bufLen; bufLen = ptr2 - ptr1;char *ptr1; char *ptr2; UINT32 bufLen; bufLen = ptr2 - ptr1; - alignBytes
-
Use
Do not usealignBytes = (unsigned short) ((size_t) address % 16);void *address; unsigned short alignBytes; alignBytes = (unsigned short) ((UINT32) address % 16); - len
-
Use
Do not uselen = (UINT32) ((char *) address2 - (char *) address1);void *address1; void *address2; UINT32 len; len = (UINT32) ((char *) address2 - (char *) address1); - sscanf
-
Use
Do not useMQLONG SBCSprt; sscanf(line, "%d", &SBCSprt);MQLONG SBCSprt; sscanf(line, "%1d", &SBCSprt);%ldtries to put an 8-byte type into a 4-byte type; only use%lif you are dealing with an actuallongdata type. MQLONG, UINT32 and INT32 are defined to be four bytes, the same as aninton all IBM® MQ platforms:
![[AIX]](ngaix.gif)