Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C

uint64_t — exactly 64-bit unsigned integer type

uint64_t from <stdint.h> stores values from 0 to 18446744073709551615. Availability of this exact-width type depends on the implementation.

Version: C23; repository compiler flag, production runtime not attested

Syntax

#include <stdint.h>
uint64_t name;

uint64_t is a type name from <stdint.h>: exactly 64 value bits, with no padding bits. Its range is 0–18446744073709551615 (UINT64_MAX). The type is optional; an implementation must provide it if it has a suitable integer type without padding bits. The required uint_least64_t provides at least 64 bits.

Do not assume it is unsigned long or that sizeof(uint64_t) is 8: a C byte need not contain 8 bits. Print it using PRIu64 from <inttypes.h>.

The example printed 0 after ++value in the test environment, but that result is not guaranteed on every implementation. If uint64_t is unsigned short and int has exactly 64 value bits plus a sign bit, the integer promotions convert value to int. Adding 1 to the value UINT64_MAX then causes signed overflow and thus undefined behavior, before any conversion back to uint64_t. Converting a computed integer value to uint64_t reduces it modulo 2^64, but that rule does not prevent overflow during the preceding calculation.

Examples

#include <stdint.h>
#include <inttypes.h>
#include <stdio.h>

#ifndef UINT64_MAX
#error "uint64_t is required"
#endif

int main(void)
{
    uint64_t value = UINT64_MAX;
    printf("%" PRIu64 "\n", value);
    ++value;
    printf("%" PRIu64 "\n", value);
    return 0;
}

Result

18446744073709551615
0

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources