currently I’m working on a simple ZIG bootloader for a custom kernel (it will become open-source after the first time it’s working) and I am using a GitHub Repository as idea. After the last question AndrewCodeDev said “Keep us posted” and I have just one question after the other
So, in src/bootloader/src/loader.c line 40 I found the (GNU EFI) #define function EFI_SIZE_TO_PAGES, which led me to a quick code search.
I discovered this function at inc/efidef.h line 208 and just used zig translate-c.
After a bit clean-up, it looked like the following:
In C that bitmask & operation is automatically converted to a boolean value – 0 is considered false, non-0 is true. You just have to make this conversion explicit:
if ((value & efi_page_mask) > 0) 1 else 0
(and maybe you don’t need all those parenthesis in there).
I believe the problem is that both 1 and 0 are of type comptime_int, so it’s trying to evaluate the if condition at comptime since it thinks the result type of the if expression is comptime_int.
Another way to resolve it would be to use @as to give the 1 / 0 a type other than comptime_int (e.g. @as(@TypeOf(value), 1))
@as doesn’t do conversion between bool and integer types. @as is intended to be always safe, no matter what, and I guess treating a bool as an integer doesn’t qualify as such.