Open Rexicon226 opened 9 months ago
Take this C for example:
#include <stdio.h> int main() { void *x = (void *)-1; printf("ptr: %p\n", x); }
when compiled with gcc the result is:
gcc
ptr: 0xffffffffffffffff
however, when compiled with translate-c
translate-c
out.zig:295:55: error: type 'usize' cannot represent integer value '-1' var x: ?*anyopaque = @as(?*anyopaque, @ptrFromInt(-@as(c_int, 1)));
the solution would be to use -% wrapping negation for the -1 I guess.
-%
-1
If you wonder about real world uses, I stumbled upon this in the most unlikely place ever. mmap. Their MAP_FAILED is literally a -1 void pointer😭
mmap
MAP_FAILED
here
Take this C for example:
when compiled with
gcc
the result is:however, when compiled with
translate-c
the solution would be to use
-%
wrapping negation for the-1
I guess.