zig icon indicating copy to clipboard operation
zig copied to clipboard

translate-c: error: use of undeclared identifier 'struct_name'

Open Ristovski opened this issue 3 years ago • 0 comments

Zig Version

0.11.0-dev.85+694d8831c

Steps to Reproduce and Observed Behavior

zig translate-c fails to translate a fairly common macro found in many headers:

#define STRUCTIFY(name) struct name
$ zig translate-c test.h > test.zig && zig ast-check test.zig
test.zig:471:48: error: use of undeclared identifier 'struct_name'
pub inline fn STRUCTIFY(name: anytype) @TypeOf(struct_name) {
                                               ^~~~~~~~~~~

The translated output is the following:

pub inline fn STRUCTIFY(name: anytype) @TypeOf(struct_name) {
    _ = @TypeOf(name);
    return struct_name;
}

Expected Behavior

Both zig translate-c and @cInclude'ing the header should work.

Ristovski avatar Nov 06 '22 20:11 Ristovski