4 ms·
What's the point of doing this in "Zig" instead of C, the traditional choice for this kind of thing?
by drnick1 8mo ago
What's the point of doing this in "Zig" instead of C, the traditional choice for this kind of thing?
- mitchellh 8mo agoFun?
- nickmonad 8mo agoNot allowed.
- deleted 8mo ago[deleted]
- toast0 8mo agoBecause you can is a pretty traditional reason. Zig is supposed to be an improvement upon C, so doing C things with it seems reasonable. Kind of neat that there's no need for a separate assembly file although there is inline assembly. Might get better (or worse) syntax support for separate assembly files? But it doesn't make a big difference until there's more features that need it (interrupts, threads/processes and maintaining their stacks, syscalls, starting other processors, etc)
- 6r17 8mo agoWhat's the point writing another kernel in C ???
- lelanthran 8mo agoConsidering that we are talking about experimental toys which have lower odds of seeing production than of you winning a national lottery jackpot, the point of writing it in C would be the same as the point of writing it in anything else - IOW, the kernel is the objective, not the language used to write it. .
- mghackerlady 8mo agoYeah, but even if I'm doing something for fun I do want to be a bit unique with it. Anyone who's interested enough in osdev to build something for baremetal has at least attempted a unix-like kernel in C
- deleted 8mo ago[deleted]
- 6r17 8mo agoIf you read yourself you'll realize your answer i highly toxic, quiet honestly completely irrelevant, discouraging other people from doing what they like. I would get rid of people with your attitude, you are the kind of problem I don't want to have to deal with and more than that, I don't want to have juniors have to deal with you. Please realize that you had your chance and you played it. Nobody ow you an explanation if you can't even get basics up.
- SpecialistK 8mo agoWhat in the sweet chili dipping sauce did I walk into? drnick1 says why "Zig" not C? [I took the quotation marks as dismissive of Zig, but I could be misreading that] 6r17 says why do it in C? lelanthran says the language is mostly irrelevant, it's a fun experiment. 6r17 blows off the handle and starts calling people toxic and being really unpleasant. Nothing in this comment chain seems to justify even 1/10th of the vitriol espoused.
- 6r17 8mo ago"Considering that we are talking about experimental toys which have lower odds of seeing production than of you winning a national lottery jackpot"
- SpecialistK 8mo agoIf you think that quote above is at all proportionate or justifies your toxicity, we have nothing else to discuss.
- pmarreck 8mo agobecause Zig is simply a better C, often faster (normally at least as fast), but with way more safety guarantees or at least things preventing the vast majority of traditional C footguns from happening
- bjourne 8mo agoZig is not faster than C.
- lionkor 8mo agoWould you say its always slower, or always faster?
- flohofwoe 8mo agoThe optimization work happens in the LLVM backend, so in most cases (and using the same optimization and target settings - which is an important detail, because by default Zig uses more aggressive optimization options than Clang), similar Zig and C code translates to the exact same machine code (when using Clang to build the C code). The same should be true for any compiled language sitting on top of LLVM btw, not just C vs Zig.
- bjourne 8mo agoNo. I will continue my crusade against blanket statements about performance.
- pmarreck 8mo agoGee, good thing I didn't make a blanket statement and qualified it by saying "often", which is true, my contrarian dude. https://tigerbeetle.com https://tigerbeetle.com wouldn't have chosen it unless they found it faster than C- and there's a significant quantity of money riding on that decision, so it likely wasn't done lightly at all. The rest, you can google yourself, but in short, sorry to tell you that it is sometimes faster. Often, sometimes, some portion of the time.
- jandrewrogers 8mo agoZig is essentially a substantially improved and enhanced C, both in character and intent. There is a lot to recommend it for applications where you might otherwise use C.
- moonlion_eth 8mo agobecause zig is lower level than c
- kunley 8mo agoI guess one of good reasons is easy cross-compilation. But also, I can see some amount of weird hooray optimism in this project, like: totally confusing claim that the thing is bare metal when it's still being run under an emulator; also, calling it a kernel is a huge overstatement
- flohofwoe 8mo agoIn this case, better tooling and consistency. E.g. the small block of inline assembly would already be trouble for some C compilers.
- AndyKelley 8mo agobitpacked structs, good enums, arbitrary sized integers, optionals + non-nullable pointers, fast compiler, zig fmt, unit testing, ability to use standard library and the rest of the third-party ecosystem on freestanding, std.ArrayList, std.AutoArrayHashMap, std.MultiArrayList, std.crypto, more productive type system, comptime, SIMD, slices, labeled switch continue, error handling, custom panic handler, stack traces on freestanding, error return traces, zero bit types, the build system, package management, aligned pointers, untagged union safety, multi-object for loops, inline switch cases, semantically guaranteed inline functions, inline loops
- kennykartman 8mo agoBecause Zig is the future, Rust has clearly failed and C is simply obsolete in 2026. The rest doesn't even matter.
- deleted 8mo ago[deleted]