espsss / reference / quick / type-sizes

C/C++ type sizes on ESP32

All ESP32 chips use a 32-bit data model, but Xtensa and RISC-V differ in long double and wchar_t, and int32_t is long rather than int. Values from the GCC 14.2.0 target sources, the RISC-V psABI and the ESP-IDF v5.5.5 docs, checked by compiling for both families.

In short

  • ESP32, ESP32-S2 and ESP32-S3 are Xtensa chips; ESP32-C2, C3, C5, C6, C61, H2 and P4 are RISC-V.1
  • Both families: int, long and pointers are 4 bytes; long long and double are 8 bytes; char is unsigned.2
  • int32_t is long and uint32_t is unsigned long, so %d and %u do not match them: use PRId32 / PRIu32 from <inttypes.h> or cast.3
  • time_t is 64-bit since ESP-IDF v5.0.4
  • The families differ: long double is 8 bytes on Xtensa and 16 on RISC-V; wchar_t is 2 bytes on Xtensa and 4 on RISC-V.5

Sizes

TypeXtensa: ESP32, S2, S3RISC-V: C2, C3, C5, C6, C61, H2, P4
char1 byte, unsigned51 byte, unsigned26
short2 bytes52 bytes2
int4 bytes54 bytes2
long4 bytes54 bytes2
long long8 bytes58 bytes2
float4 bytes54 bytes2
double8 bytes58 bytes2
long double8 bytes (same as double)516 bytes26
pointer4 bytes54 bytes2
size_t4 bytes, unsigned int74 bytes, unsigned int6
wchar_t2 bytes, unsigned short74 bytes, int8
time_t8 bytes48 bytes4
int32_t / uint32_tlong / unsigned long3long / unsigned long3

Every row was confirmed with static_assert and sizeof in ESP-IDF v5.5.6 builds for esp32s3 and esp32c3 and on an ESP32-S3 board with arduino-esp32 3.3.12.

printf formats for fixed-width types

The PRI macros expand to the right length modifier for the type, so the same format string works on every chip.

TypeFormatNote
int8_t / uint8_tPRId8 / PRIu8 / PRIx8#include <inttypes.h>9
int16_t / uint16_tPRId16 / PRIu16 / PRIx16#include <inttypes.h>9
int32_t / uint32_tPRId32 / PRIu32 / PRIx32not %d / %u / %x3
int64_t / uint64_tPRId64 / PRIu64 / PRIx649
intptr_t / uintptr_tPRIdPTR / PRIuPTR / PRIxPTR9
size_t%zu10
time_t%lld with a cast to long longno PRI macro for time_t4
#include <inttypes.h>
#include <time.h>

static_assert(sizeof(time_t) == 8, "64-bit time_t");

void setup() {
  Serial.begin(115200);
  int32_t temp = -40;
  uint32_t big = 4000000000UL;
  uint64_t total = 5000000000ULL;
  size_t len = 12;
  time_t now = time(nullptr);

  Serial.printf("temp=%" PRId32 " big=%" PRIu32 " hex=%" PRIx32 "\n", temp, big, big);
  Serial.printf("total=%" PRIu64 " len=%zu\n", total, len);
  Serial.printf("now=%lld\n", (long long)now);  // no PRI macro for time_t
  Serial.printf("temp=%ld\n", (long)temp);      // or cast to a type with a known format
}

void loop() {}

Pitfalls

%d with int32_t

A format mismatch: in an ESP-IDF build it is an error (-Werror=format=); in Arduino the default warning flags are -w, so it compiles without a message and only shows up with warnings enabled.3

abs() on time_t

abs() takes an int; for 64-bit values such as time_t use llabs().3

int32_t is not int

They are different types even though both are 4 bytes, which matters for overloads, templates and pointer types (int32_t* is not int*).3

Binary layouts with long double or wchar_t

A struct with long double or wchar_t has a different size on Xtensa and RISC-V chips, so it should not be sent or stored as raw bytes between them.5

Sources

Each number links here; open “What it confirms” for the exact quotes. Checked 2026-11-28.

  1. ESP-IDF v5.5.5: Kconfig primary
    What it confirms (1)
    • C/C++ type sizes on ESP32: in short “default "y" if IDF_TARGET="esp32" select IDF_TARGET_ARCH_XTENSA … default "y" if IDF_TARGET="esp32s2" select FREERTOS_UNICORE select IDF_TARGET_ARCH_XTENSA … default "y" if IDF_TARGET="esp32s3" select IDF_TARGET_ARCH_XTENSA … default "y" if IDF_TARGET="esp32c2" select FREERTOS_UNICORE select IDF_TARGET_ARCH_RISCV … default "y" if IDF_TARGET="esp32c3" select FREERTOS_UNICORE select IDF_TARGET_ARCH_RISCV … default "y" if IDF_TARGET="esp32c5" select FREERTOS_UNICORE select IDF_TARGET_ARCH_RISCV … default "y" if IDF_TARGET="esp32c6" select FREERTOS_UNICORE select IDF_TARGET_ARCH_RISCV … default "y" if IDF_TARGET="esp32c61" select FREERTOS_UNICORE select IDF_TARGET_ARCH_RISCV … default "y" if IDF_TARGET="esp32h2" select FREERTOS_UNICORE select IDF_TARGET_ARCH_RISCV … default "y" if IDF_TARGET="esp32p4" select IDF_TARGET_ARCH_RISCV”
  2. RISC-V ELF psABI v1.0: riscv-cc.adoc (C/C++ type sizes for ILP32) primary
    What it confirms (10)
    • C/C++ type sizes on ESP32: in short “| int | 4 | 4 … | long | 4 | 4 … | void * | 4 | 4 … | long long | 8 | 8 … | double | 8 | 8 … `char` is unsigned. … #define DEFAULT_SIGNED_CHAR 0”
    • C/C++ type sizes on ESP32: char / RISC-V: C2, C3, C5, C6, C61, H2, P4 “| char | 1 | 1 … `char` is unsigned.”
    • C/C++ type sizes on ESP32: short / RISC-V: C2, C3, C5, C6, C61, H2, P4 “| short | 2 | 2”
    • C/C++ type sizes on ESP32: int / RISC-V: C2, C3, C5, C6, C61, H2, P4 “| int | 4 | 4”
    • C/C++ type sizes on ESP32: long / RISC-V: C2, C3, C5, C6, C61, H2, P4 “| long | 4 | 4”
    • C/C++ type sizes on ESP32: long long / RISC-V: C2, C3, C5, C6, C61, H2, P4 “| long long | 8 | 8”
    • C/C++ type sizes on ESP32: float / RISC-V: C2, C3, C5, C6, C61, H2, P4 “| float | 4 | 4”
    • C/C++ type sizes on ESP32: double / RISC-V: C2, C3, C5, C6, C61, H2, P4 “| double | 8 | 8”
    • C/C++ type sizes on ESP32: long double / RISC-V: C2, C3, C5, C6, C61, H2, P4 “| long double | 16 | 16”
    • C/C++ type sizes on ESP32: pointer / RISC-V: C2, C3, C5, C6, C61, H2, P4 “| void * | 4 | 4”
  3. ESP-IDF v5.5.5 docs: Migration from 4.4 to 5.0, GCC (int32_t and uint32_t) primary
    What it confirms (7)
    • C/C++ type sizes on ESP32: in short “users will need to replace placeholders such as %i and %x with PRIi32 and PRIx32 respectively … In common, int32_t and int, as well as uint32_t and unsigned int, are different types.”
    • C/C++ type sizes on ESP32: int32_t / uint32_t / Xtensa: ESP32, S2, S3 “have been changed from the previous int and unsigned int to long and unsigned long respectively for the Xtensa compiler”
    • C/C++ type sizes on ESP32: int32_t / uint32_t / RISC-V: C2, C3, C5, C6, C61, H2, P4 “This change now matches upstream GCC which long integers for int32_t and uint32_t on Xtensa, RISC-V, and other architectures.”
    • C/C++ type sizes on ESP32: int32_t / uint32_t “users will need to replace placeholders such as %i and %x with PRIi32 and PRIx32 respectively … PRIdx”
    • C/C++ type sizes on ESP32: pitfall: %d with int32_t “error: format '%u' expects argument of type 'unsigned int', but argument 3 has type 'uint32_t' {aka 'long unsigned int'} [-Werror=format=] … compiler.warning_flags=-w”
    • C/C++ type sizes on ESP32: pitfall: abs() on time_t “The function abs() from stdlib.h takes int argument. Please use llabs() for types that are intended to be 64-bit. It is particularly important for time_t.”
    • C/C++ type sizes on ESP32: pitfall: int32_t is not int “In common, int32_t and int, as well as uint32_t and unsigned int, are different types.”
  4. ESP-IDF v5.5.5 docs: System Time (64-bit time_t) primary
    What it confirms (4)
    • C/C++ type sizes on ESP32: in short “ESP-IDF uses a 64-bit signed integer to represent time_t starting from release v5.0”
    • C/C++ type sizes on ESP32: time_t / Xtensa: ESP32, S2, S3 “ESP-IDF uses a 64-bit signed integer to represent time_t starting from release v5.0”
    • C/C++ type sizes on ESP32: time_t / RISC-V: C2, C3, C5, C6, C61, H2, P4 “ESP-IDF uses a 64-bit signed integer to represent time_t starting from release v5.0”
    • C/C++ type sizes on ESP32: time_t “ESP-IDF uses a 64-bit signed integer to represent time_t … signed char | short | int | long | long long”
  5. GCC 14.2.0: gcc/config/xtensa/xtensa.h primary
    What it confirms (11)
    • C/C++ type sizes on ESP32: in short “#define LONG_DOUBLE_TYPE_SIZE 64 … #define WCHAR_TYPE_SIZE 16 … | long double | 16 | 16 … #define WCHAR_TYPE "int"”
    • C/C++ type sizes on ESP32: char / Xtensa: ESP32, S2, S3 “#define DEFAULT_SIGNED_CHAR 0”
    • C/C++ type sizes on ESP32: short / Xtensa: ESP32, S2, S3 “#define SHORT_TYPE_SIZE 16”
    • C/C++ type sizes on ESP32: int / Xtensa: ESP32, S2, S3 “#define INT_TYPE_SIZE 32”
    • C/C++ type sizes on ESP32: long / Xtensa: ESP32, S2, S3 “#define LONG_TYPE_SIZE 32”
    • C/C++ type sizes on ESP32: long long / Xtensa: ESP32, S2, S3 “#define LONG_LONG_TYPE_SIZE 64”
    • C/C++ type sizes on ESP32: float / Xtensa: ESP32, S2, S3 “#define FLOAT_TYPE_SIZE 32”
    • C/C++ type sizes on ESP32: double / Xtensa: ESP32, S2, S3 “#define DOUBLE_TYPE_SIZE 64”
    • C/C++ type sizes on ESP32: long double / Xtensa: ESP32, S2, S3 “#define LONG_DOUBLE_TYPE_SIZE 64 … #define DOUBLE_TYPE_SIZE 64”
    • C/C++ type sizes on ESP32: pointer / Xtensa: ESP32, S2, S3 “#define Pmode SImode … #define UNITS_PER_WORD 4”
    • C/C++ type sizes on ESP32: pitfall: Binary layouts with long double or wchar_t “#define LONG_DOUBLE_TYPE_SIZE 64 … #define WCHAR_TYPE_SIZE 16 … | long double | 16 | 16 … #define WCHAR_TYPE "int"”
  6. GCC 14.2.0: gcc/config/riscv/riscv.h primary
    What it confirms (3)
    • C/C++ type sizes on ESP32: char / RISC-V: C2, C3, C5, C6, C61, H2, P4 “#define DEFAULT_SIGNED_CHAR 0”
    • C/C++ type sizes on ESP32: long double / RISC-V: C2, C3, C5, C6, C61, H2, P4 “#define LONG_DOUBLE_TYPE_SIZE 128”
    • C/C++ type sizes on ESP32: size_t / RISC-V: C2, C3, C5, C6, C61, H2, P4 “#define SIZE_TYPE (POINTER_SIZE == 64 ? "long unsigned int" : "unsigned int")”
  7. GCC 14.2.0: gcc/config/xtensa/elf.h primary
    What it confirms (2)
    • C/C++ type sizes on ESP32: size_t / Xtensa: ESP32, S2, S3 “#define SIZE_TYPE "unsigned int"”
    • C/C++ type sizes on ESP32: wchar_t / Xtensa: ESP32, S2, S3 “#define WCHAR_TYPE "short unsigned int" … #define WCHAR_TYPE_SIZE 16”
  8. GCC 14.2.0: gcc/defaults.h primary
    What it confirms (1)
    • C/C++ type sizes on ESP32: wchar_t / RISC-V: C2, C3, C5, C6, C61, H2, P4 “#define WCHAR_TYPE "int"”
  9. cppreference: Fixed width integer types (<cstdint>, <cinttypes> format macros) primary
    What it confirms (4)
    • C/C++ type sizes on ESP32: int8_t / uint8_t “Each of the PRI macros listed here is defined if and only if the implementation defines the corresponding typedef name. … PRIdx … PRIux … PRIxx”
    • C/C++ type sizes on ESP32: int16_t / uint16_t “PRIdx … PRIux … PRIxx … N is typically 8, 16, 32 or 64”
    • C/C++ type sizes on ESP32: int64_t / uint64_t “std::printf("%+" PRId64 "\n", INT64_MIN); … PRIux”
    • C/C++ type sizes on ESP32: intptr_t / uintptr_t “PRIdPTR … PRIuPTR … PRIxPTR”
  10. cppreference: std::printf, std::fprintf (length modifiers) primary
    What it confirms (1)
    • C/C++ type sizes on ESP32: size_t “For the z modifier, the expected argument type is the signed version of std::size_t. … unsigned long long | std::uintmax_t | std::size_t”