Skip to content

Missing support for MSVC integer suffixes like i64, ui64 #956

@castholm

Description

@castholm
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>

bool f(void) {
    return (size_t)0 < SIZE_MAX;
}
zig translate-c foo.h -lc -target x86_64-windows-msvc
error: translation failure
foo.h:6:24: error: invalid suffix 'ui64' on integer constant
    return (size_t)0 < SIZE_MAX;
                       ^
C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.44.35207\include\stdint.h:108:26: note: expanded from here
        #define SIZE_MAX 0xffffffffffffffffui64

i64 and ui64 (case-insensitive) are officially documented MSVC integer suffix extensions.
https://learn.microsoft.com/en-us/cpp/c-language/c-integer-constants?view=msvc-170

Apparently i8, ui8, i16, ui16, i32 and ui32 are also supported, but undocumented, and are used by MSVC headers for e.g. #define UINT8_MAX 0xffui8.
https://stackoverflow.com/questions/33659846/microsoft-integer-literal-extensions-where-documented

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions