반응형

- 사용하기 위해선,

먼저 int8_t를 이용하려면 아래의 코드를 통해, stdint.h 헤더파일을 포함해야한다.

#include <stdint.h>

 

- 사용하는 이유

1. 모든 플랫폼에서 동일한 bit 수를 사용하기 위해서 입니다. 즉, 이식성을 위해서 사용합니다.

2. 확실하게 1) 비트 수, 2) signed를 표현하기 위해서 사용합니다. uint8_t는 8비트의 unsign 타입이라는 걸 알 수 있습니다. 개발자로 하여금 헷갈릴 이유가 없어집니다.

3. 임베디드 시스템에서 메모리 사용 관리를 위해, 마이크로하게 신경 써줘야하는 경우에 해당 데이터 타입을 많이 사용합니다. 혹은 네트워크 패킷 처리 등 octect 단위로 신경 써줘야 하는 부분에 많이 사용됩니다.

 

 

 

처음엔 stdint.h 헤더는 구체적인 길이를 가진 integer 타입들의 집합을 정의합니다. 또한, 그 헤더는 해당 매크로들의 집합을 정의합니다.

 그것은 또한 매크로들을 정의하는데요. 어떤 매크로냐면, 그 매크로는(standard header들)표준 헤더 안에서 정의된 타입들에 상응하는 integer 타입들의 제한들을 구체화합니다.

 

 

 

The  header shall declare sets of integer types having specified widths, and shall define corresponding sets of macros. It shall also define macros that specify limits of integer types corresponding to types defined in other standard headers.

 

Types are defined in the following categories:

  • Integer types having certain exact widths
  • Integer types having at least certain specified widths
  • Fastest integer types having at least certain specified widths
  • Integer types wide enough to hold pointers to objects
  • Integer types having greatest width

 

int8_t
int16_t
int32_t
uint8_t
uint16_t
uint32_t

 

 

 

참고자료/출처

https://pubs.opengroup.org/onlinepubs/009695399/basedefs/stdint.h.html

 

https://educoder.tistory.com/entry/cc-int8t-uint8t-int16t-uint16t

반응형

'C > C' 카테고리의 다른 글

아스키코드표 (ASCII Code table)  (0) 2022.07.18
[C] typedef 사용 예  (0) 2022.05.30
[C] 헤더파일에 구조체 선언하기  (0) 2022.05.02
[C] shm_open  (0) 2022.04.22
구조체와 공용체 (Struct와 Union)에 대한 고찰  (2) 2022.02.23