You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Compile and run with: zig build-exe --library ncurses main.zig && ./main
The output is "COLORS: 0". By commenting in line 9 of main.zig, the output changes to "COLORS: 256". Tested on macOS 10.15.4 using zig 0.5.0+1568470c4, verified on Linux.
I managed to create this problem without pointers (with a warn() instead of the pure read), but build this example first. My suspicion is that the access triggers some kind of runtime behavior, and that explicitly marking the COLORS assignment in start_color() as a runtime operation would fix this, but I can't prove it yet.
A runtime equivalent to comptime might be a good idea anyhow.
The text was updated successfully, but these errors were encountered:
Ncurses defines an external variable named COLORS and so does import.zig. The compiler is dumb and clumps together all the (scope-)global variables together without any kind of namespacing, this means that any variable named COLORS will alias the other with the same name.
Adding const pCLRS = &c.COLORS; generates a nice conflict that translates into the following LLVM IR:
To be clear the intended behavior here is that pub vars cannot clobber external symbols. The pub var COLORS is the one that is supposed to get the mangling/namespacing.
andrewrk
added
the
stage1
The process of building from source via WebAssembly and the C backend.
label
Apr 6, 2020
LemonBoy
added a commit
to LemonBoy/zig
that referenced
this issue
Apr 7, 2020
While playing around with wrapping ncurses, I ran into the following problem:
Given the following files:
main.zig:
import.zig:
Compile and run with:
zig build-exe --library ncurses main.zig && ./main
The output is "COLORS: 0". By commenting in line 9 of
main.zig
, the output changes to "COLORS: 256". Tested on macOS 10.15.4 using zig 0.5.0+1568470c4, verified on Linux.I managed to create this problem without pointers (with a
warn()
instead of the pure read), but build this example first. My suspicion is that the access triggers some kind of runtime behavior, and that explicitly marking theCOLORS
assignment instart_color()
as a runtime operation would fix this, but I can't prove it yet.A runtime equivalent to
comptime
might be a good idea anyhow.The text was updated successfully, but these errors were encountered: