요약 : 반복문을 사용할때 int의 경우 오버플로우를 발생 시킬 수 있다.(범위를 벗어남) 안전하게 사용하기 위해서 size_t를 사용할 수 있다.


주의할 점 : unsigned_int 타입이 "아니다" unsigned 자료형을 반환한다.  sizeof()가 반환하는 타입으로 , 해당 시스템에서 어떤 값 객체가 차지할 수 있는 이론적인 최대 크기를 표현하는 자료형 이다. 32비트 , 64비트 등 시스템에 따라 크기가 변화한다.


size_t가 필요한 이유는 1바이트로 만들 수 있는 최대 크기의 array(배열) 라든지, 하나의 값이 가질 수 있는 최대의 크기를 범위로 하는 값을 다룰 때 필요하다.


또 한개의 파일 크기가 4GB가 넘거나 큰 데이터를 다뤄야 한다면 필수적으로 알고 있어야 한다.


원문


size_t is an unsigned data type defined by several C/C++ standards, e.g. the C99 ISO/IEC 9899 standard, that is defined in stddef.h.1 It can be further imported by inclusion of stdlib.h as this file internally sub includes stddef.h.


This type is used to represent the size of an object. Library functions that take or return sizes expect them to be of type or have the return type of size_t. Further, the most frequently used compiler-based operator sizeof should evaluate to a constant value that is compatible with size_t. As an implication, size_t is a type guaranteed to hold any array index.

'기타 > ETC' 카테고리의 다른 글

Unity Gradle Build 에러시  (0) 2018.07.02
유니티 안드로이드 APK 빌드 하기 (Unity to Android APK)  (1) 2017.08.16
API 에러창 띄우기  (0) 2017.04.20

+ Recent posts