zig
zig copied to clipboard
Support _Atomic in translate-c
_Atomic
data types are available in C11 that ensures atomic read and load. I'm not sure how to implement this in Zig.
Zig Version
0.10.0-dev.1427+ad5770eba
Steps to Reproduce
Save the text below as test.c
:
_Atomic(int) hi;
Then run zig translate-c test.c
.
Expected Behavior
No error
Actual Behavior
> zig translate-c test.c | grep hi
pub const hi = @compileError("unable to resolve variable type"); // test.c:1:14
https://ziglang.org/documentation/master/#atomicLoad https://ziglang.org/documentation/master/#atomicStore
The problem is that _Atomic
is a type attribute, where @atomicLoad
is usage of a term. If _Atomic(uint8_t)
is translated to u8
, then assignments to atomic variables need to use @atomicStore
.
This is fine on x86 and some CPU architectures where load/store of register-sized integer is always atomic, but what problem will C non-compilance cause down the road? Should we even care about this? Maybe generate compile-time warnings is fine.
Partially related https://github.com/ziglang/zig/issues/4248
Probably related #5101
This affects Nuitka (the Python compiler) and Python 3.11 or higher. We as a project want to use zig as a backend C compiler, with long term hope of being able to use it exclusively. I am commenting here more follow. Writing a compiler myself, I know how hard this issue can be to solve for you, seeing a 0.15 milestone probably means, this will take a while.
Nuitka requires C11 more or less with modern Python.