IT TIP

stdint.h와 inttypes.h의 차이점

itqueen 2020. 11. 3. 19:36
반응형

stdint.h와 inttypes.h의 차이점


stdint.h와 inttypes.h의 차이점은 무엇입니까?

이들 중 어느 것도 사용되지 않으면 uint64_t는 인식되지 않지만 둘 중 하나를 사용하면 정의 된 유형입니다.


inttypes.h에 대해서는 wikipedia 문서를 참조하십시오.

최소한의 정의 세트에 stdint.h를 사용하십시오. printf, scanf 등에서 이들에 대한 이식 가능한 지원이 필요한 경우 inttypes.h를 사용하십시오.


stdint.h

C99의 지정된 너비 정수 유형 (예 : "int32_t", "uint16_t"등)으로 작업하려는 경우이 파일을 포함하는 것이 "최소 요구 사항"입니다. 이 파일을 포함하면 이러한 유형의 정의를 가져 오므로 변수 및 함수 선언에서 이러한 유형을 사용하고 이러한 데이터 유형으로 작업을 수행 할 수 있습니다.

inttypes.h

이 파일을 포함하면 stdint.h가 제공하는 모든 것을 얻을 수 있지만 (inttypes.h에는 stdint.h가 포함되어 있기 때문에) printf 및 scanf (및 "fprintf,"fscanf "등을 수행 할 수있는 기능도 제공됩니다.) 예를 들어 "PRIu16"매크로를 가져 와서 다음과 같이 uint16_t 정수를 인쇄 할 수 있습니다.

#include <stdio.h>
#include <inttypes.h>
int main (int argc, char *argv[]) {

    // Only requires stdint.h to compile:
    uint16_t myvar = 65535;

    // Requires inttypes.h to compile:
    printf("myvar=%" PRIu16 "\n", myvar);  
}

참고 URL : https://stackoverflow.com/questions/7597025/difference-between-stdint-h-and-inttypes-h

반응형