C bindings with UInt32 or other constant type

How do you generate Constants that are not Int32

@[Link("somelib")]
lib LibSomeLib
  PROP_ID_SECURE_MIN = 26608
  PROP_ID_SECURE_MAX = 26623
end

Can you do it like this?

@[Link("somelib")]
lib LibSomeLib
  PROP_ID_SECURE_MIN : UInt32 =  26608
  PROP_ID_SECURE_MAX : UInt32 =  26623
end

I want to convert these bindings for zig to Crystal

pub const PROP_ID_SECURE_MIN = @as(u32, 26608);
pub const PROP_ID_SECURE_MAX = @as(u32, 26623);
1 Like

You would want to use the suffix for the integer type you want. E.g. PROP_ID_SECURE_MIN = 26608_u32.

Ref: Integers - Crystal

1 Like

The corresponding GitHub issue is Constants with type declarations · Issue #13443 · crystal-lang/crystal · GitHub