-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Does zig reimplement some part of libc directly in zig? #7
Comments
Append e.g. const std = @import("std");
pub fn main() !void {
const arr = try std.heap.c_allocator.alloc(u8,1024);
std.debug.print("{}",.{arr.len});
}
|
extern fn puts([*:0]const u8) c_int;
pub fn main() void {
_ = puts("Hello World!");
}
|
As other's already said, if you're using the
As you mentioned, there is a community effort to implement libc completely in Zig, with the idea being to integrate it into Zig itself so that it generates the appropriate version depending on which platform you compile to. Although I'm not really sure what the state of that is, or if they'll really end up shipping it with Zig.
Linux is one of the only operating systems where syscalls are guaranteed to be stable between versions. As such, when compiling to Linux, Zig will take every opportunity to avoid going through libc, and invokes the syscalls directly. On platforms where libc is the only "standard" way to interact with the OS, Zig will fallback to using libc. |
Thank you for your advice. I know that I should explicitly add After re-reading my question, I realize the most important bit is about
This is interesting and helpful. I also read the following statement by Andrew in a zig issue.
So I guess my question is more about knowing what is the exact purpose of It seems there are answers in
I also see that termios is brought in scope with
And system is set to
In the above code, the branch And with this context and to refine my initial question, can I consider that in If so and when Thanks a lot. The relationship between zig and |
If you take a look at the standard library in the repo you can see that in
As I understand it, yeah. Scanning through
|
lots of great info here, ziglang/zig#2879 is also relevant |
I am trying to understand the relationship with zig and libc. I get that for example it has different behaviors according to libc implementations. With glibc, it will generate the headers and dynamically link glibc. For musl, it embeds the implementation directly so it can generate static builds.
I have a few subquestions, however.
lib/std/os/linux.zig
? I see that it has the implementation for functions such astcgetattr
, which is normally defined in<termios.h>
. Does zig already reimplement some parts of libc directly in zig then?To give more context for this last one, I am trying to use
termios
for an application that would have total control over the terminal. To metermios
is part of libc. In my zig code, I see that I can usestd.os.termios
. It seems to be zig code however, and when I compile it without any special flags, it generates a static build. So I don't understand why I can usetermios
without involving any libc.And a complementary question: if it happens that this bit of libc has been reimplemented in zig, why? And for learning purposes, can I force to use
termios
from libc instead somehow?Thanks!
The text was updated successfully, but these errors were encountered: