C data types
C 프로그래밍 언어에서 자료형은 데이터의 특징을 결정하는 메모리 위치나 변수의 선언이다.
C 언어는 정수와 실수형과 같은 기초적인 산술형, 그리고 배열과 복합형을 만드는 문법을 제공한다.
Standard Data Type Limits
- Standard Data Type Limits
- C - Data Types
- Data Type Ranges | Microsoft Docs
- Standard Data Type Limits - FreeBASIC Documentation
- 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 32bit 에서 64bit로 소스호환을 위한 고려사항 정리
- 64Bit 개발 이야기
- http://redmist.springnote.com/pages/6717419.xhtml
- [http://msdn.microsoft.com/ja-jp/library/bb147385(VS.85.aspx 게임개발자를 위한 64Bit 프로그래밍]
32bit 환경에서 64bit 환경으로 옮겨가면서 달라진 변수형에 대하여 정리한다. 아래의 내용은 직접 테스트한 결과를 출력한다.
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 |
문제가 되는 코드들
- 크기가 다른 변수형에 대한 포인터를 사용한 경우. (스택붕괴가 우려되는 경우)
- DWORD 정의.
- x86계열 어셈블리 호환성.
- Implementation 함수의 잘못된 고려. (size_t 등의 의미를 전혀 활용하지 못한경우 등)
- 구조체 크기 정렬.
- Pre-define 으로 64bit 를 검출.
캐쉬(cache) 조정
gcc 사용자라면 64bit 에서 보다 높은 성능을 위하여 __builtin_expect((long)(m_expression),(long)(m_value))
내장함수도 한번 검토해보시면 좋을것 같습니다. 이것은 조건식이 거의 실행되지 않을 확률 또는 실행될 확률을 조정함으로써 컴파일러로 하여금 Cache 의 최적사용을 위한 최적화가 가능해지도록 유도될수 있습니다. 64bit 기계어 코드를 보시면 이러한 Cache 를 효과적으로 사용할수 있도록 하는 방법이 제공되기 때문에 잘만 사용하면 성능이 극대화 될것으로 생각됩니다.