ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
34.95k stars 2.55k forks source link

Issue translating raylib.h, unexecpted token Id{ .LBrace = void } #5887

Closed creikey closed 4 years ago

creikey commented 4 years ago

Full file in question: https://github.com/raysan5/raylib/blob/7ef114d1da2c34a70bba5442497103441647d8f3/src/raylib.h

Isolated snippet that reproduces the error ( from line 118 to 128 ):

// NOTE: MSC C++ compiler does not support compound literals (C99 feature)
// Plain structures in C++ (without constructors) can be initialized from { } initializers.
#if defined(__cplusplus)
    #define CLITERAL(type)      type
#else
    #define CLITERAL(type)      (type)
#endif

// Some Basic Colors
// NOTE: Custom raylib color palette for amazing visuals on WHITE background
#define LIGHTGRAY  CLITERAL(Color){ 200, 200, 200, 255 }   // Light Gray

Translate error of interest: pub const LIGHTGRAY = @compileError("unable to translate C expr: unexpected token Id{ .LBrace = void }");

creikey commented 4 years ago

Something that I don't really understand is why zig doesn't run the preprocessor before translating the C?

Vexu commented 4 years ago

Zig does run the preprocessor before translating the C (well clang does), but doing so won't turn these macros into C expressions, it only expands them when they are used somewhere.