C data types
lastmod 2021-06-16created 2021-06-164 edits
In the C programming language, data types are declarations of memory locations or variables that determine the characteristics of the data.
The C language provides basic arithmetic types such as integer and real number types, along with syntax for building array and compound types.
Standard Data Type Limits
- Standard Data Type Limits
- C - Data Types
- Data Type Ranges | Microsoft Docs
- Standard Data Type Limits - FreeBASIC Documentation
- See climits.
Numeric Types
| Type | Size (in bits) | Format | Minimum Value | Maximum Value | Literal Suffix | Sig. Digits |
| BYTE | 8 | signed integer | -128 | +127 | 2+ | |
| UBYTE | 8 | unsigned integer | 0 | +255 | 2+ | |
| SHORT | 16 | signed integer | -32768 | +32767 | 4+ | |
| USHORT | 16 | unsigned integer | 0 | 65535 | 4+ | |
| INTEGER | 32 | signed integer | -2147483648 | +2147483647 | %, l | 9+ |
| UINTEGER | 32 | unsigned integer | 0 | 4294967295 | ul | 9+ |
| LONG | [*] | signed integer | [*] | [*] | & | [*] |
| ULONG | [*] | unsigned integer | [*] | [*] | [*] | |
| LONGINT | 64 | signed integer | -9 223 372 036 854 775 808 | +9 223 372 036 854 775 807 | ll | 18+ |
| ULONGINT | 64 | unsigned integer | 0 | +18 446 744 073 709 551 615 | ull | 19+ |
| SINGLE | 32 | floating point | [**]+/-1.401 298 E-45 | [**]+/-3.402 823 E+38 | !, f | 6+ |
| DOUBLE | 64 | floating point | [**]+/-4.940 656 458 412 465 E-324 | [**]+/-1.797 693 134 862 316 E+308 | # | 15+ |
- [*] Long and Ulong data types vary with platform. Currently, they are aliases to either Integer or LongInt and their unsigned versions, respectively.
- [**] The minimum and maximum values for the floating-point types Single and Double are, respectively, the values closest to zero and the values closest to positive and negative infinity.
C Datatype 32bit 64bit
- KLDP Considerations for source compatibility from 32bit to 64bit
- 64Bit development story
- http://redmist.springnote.com/pages/6717419.xhtml
- [http://msdn.microsoft.com/ja-jp/library/bb147385(VS.85.aspx 64Bit programming for game developers]
A summary of the variable types that changed in the move from 32bit to 64bit environments. The results below are from my own tests.
| CPU | Intel x86 | Intel x86 | Intel x86_64 | Intel x86_64 | Intel x86_64 | Intel x86_64 | Intel x86_64 |
| OS | Win7 32bit | Win7 32bit | Win7 64bit | Win7 64bit | Win7 64bit | Win7 64bit | Fedora 64bit |
| Compiler | VS9 32bit | MinGW g++ 32bit | VS10 32bit | VS10 64bit | MinGW g++ 32bit | MinGW g++ 64bit | cc 64bit |
| size_t | 4byte | 4byte | 4byte | 8byte | 4byte | 8byte | 8byte |
| ssize_t | - | 4byte | - | - | 4byte | 8byte | 8byte |
| char | 1byte | 1byte | 1byte | 1byte | 1byte | 1byte | 1byte |
| wchar_t | 2byte | 2byte | 2byte | 2byte | 2byte | 2byte | 4byte |
| short | 2byte | 2byte | 2byte | 2byte | 2byte | 2byte | 2byte |
| int | 4byte | 4byte | 4byte | 4byte | 4byte | 4byte | 4byte |
| long | 4byte | 4byte | 4byte | 4byte | 4byte | 4byte | 8byte |
| long long | 8byte | 8byte | 8byte | 8byte | 8byte | 8byte | 8byte |
| float | 4byte | 4byte | 4byte | 4byte | 4byte | 4byte | 4byte |
| double | 8byte | 8byte | 8byte | 8byte | 8byte | 8byte | 8byte |
| long double | 8byte | 12byte | 8byte | 8byte | 12byte | 16byte | 16byte |
| | 4byte | 4byte | 4byte | 8byte | 4byte | 8byte | 8byte |
Problematic code
- Using pointers to variable types of different sizes. (when stack corruption is a concern)
- DWORD definitions.
- x86-family assembly compatibility.
- Mistaken assumptions about Implementation functions. (e.g., not making use of the meaning of size_t at all)
- Struct size alignment.
- Detecting 64bit via Pre-define.
Cache tuning
If you use gcc, it may be worth looking at the __builtin_expect((long)(m_expression),(long)(m_value)) built-in function for better performance on 64bit. By adjusting the probability that a conditional expression is rarely or likely to be executed, it can lead the compiler to optimize for the best use of the Cache. Since 64bit machine code provides ways to use the Cache effectively, using this well should maximize performance.