#633·clay

Struct layout mismatch between C and C++ on MSVC

Author: kakadilaCreated Jun 20, 2026Updated Jun 24, 2026

1: Struct layout mismatch between C and C++ on MSVC

  • File : clay.h

On MSVC (without Clang), the CLAY_PACKED_ENUM macro produces different enum sizes in C and C++ compilation, causing struct layout incompatibility when the same struct is compiled by both C and C++ translation units.

Image

The C++ path uses enum : uint8_t , which correctly creates a 1-byte enum. The C MSVC path uses __pragma(pack(push, 1)) around enum , but #pragma pack only affects struct member alignment, not enum size . MSVC enums are always 4 bytes ( int ) regardless of pack pragma, so this macro is effectively a no-op.

This causes sizeof(Clay_ElementDeclaration) to be ~248 bytes in C++ vs ~272 bytes in C (MSVC), leading to data misalignment when C code writes the struct and C++ reads it, or vice versa.

2. Missing break in OVERLAY_COLOR_END render command (raylib renderer)

  • File : renderers/raylib/clay_renderer_raylib.c
Image

It seems for CLAY_RENDER_COMMAND_TYPE_OVERLAY_COLOR_END commands, to draw an unpredictable rectangle