Site Tools


wiki:h-stdint

Table of Contents

<stdint.h>

<stdint.h> provides fixed-width integer types (C99): int8_t, uint32_t, int64_t, etc., guaranteeing exact widths across platforms. Also includes intmax_t, intptr_t, and limit macros like INT32_MAX.

Use fixed-width types for binary I/O, hardware registers, and portable low-level code.

Example

This example queries the sizes of fixed-width integer types on the platform.

// compile: gcc -o stdintexample stdintexample.c
// run: ./stdintexample
// description: show fixed-width integer type sizes
 
#include <stdint.h>
#include <stdio.h>
 
int main() {
    printf("int8_t = %zu bytes\n", sizeof(int8_t));
    printf("int16_t = %zu bytes\n", sizeof(int16_t));
    printf("int32_t = %zu bytes\n", sizeof(int32_t));
    printf("int64_t = %zu bytes\n", sizeof(int64_t));
    printf("intptr_t = %zu bytes\n", sizeof(intptr_t));
    printf("INT32_MAX = %d\n", INT32_MAX);
    printf("UINT64_MAX = %llu\n", (unsigned long long)UINT64_MAX);
 
    return 0;
}
wiki/h-stdint.md · Last modified: by 127.0.0.1