zig icon indicating copy to clipboard operation
zig copied to clipboard

__builtin_constant_p: error: expected type 'bool', found 'c_int'

Open bergkvist opened this issue 2 years ago • 0 comments

Zig Version

0.10.1 (macOS, aarch64)

Steps to Reproduce and Observed Behavior

const c = @cImport({
    @cInclude("arpa/inet.h");
});

pub fn main() !void {
    _ = c.htons(8000);
}

Error message:

/Users/tobias/.cache/zig/o/cddc6b367dd0c76816e4ff1e6a11af21/cimport.zig:2171:86: error: expected type 'bool', found 'c_int'
    return @import("std").zig.c_translation.cast(__uint16_t, if (__builtin_constant_p(x)) __DARWIN_OSSwapConstInt16(x) else _OSSwapInt16(x));
                                                                 ~~~~~~~~~~~~~~~~~~~~^~~
/Users/tobias/.cache/zig/o/cddc6b367dd0c76816e4ff1e6a11af21/cimport.zig:2182:61: note: called from here
pub inline fn htons(x: anytype) @TypeOf(__DARWIN_OSSwapInt16(x)) {

Expected Behavior

No error message. htons should swap the 2 bytes in a u16 value. See:

  • https://www.daemon-systems.org/man/htons.3.html
  • https://www.daemon-systems.org/man/__builtin_constant_p.3.html

bergkvist avatar Aug 15 '23 19:08 bergkvist