I don't wanna talk about it, but I wanna talk about it...
-
Yes, it's Zig. Forgive me because I'm becoming a wordle post. :laugh: But, I just gotta say, this is how extremely easy it is to use C code in Zig...
// this is it, just do @cImport instead of @import
const c = @cImport({
@cInclude("unistd.h");
});pub fn main() void {
// as a bonus the C functions are already namespaced too
const res = c.write(2, "Hello C from Zig!", 17);
}Jeremy Falcon
-
Yes, it's Zig. Forgive me because I'm becoming a wordle post. :laugh: But, I just gotta say, this is how extremely easy it is to use C code in Zig...
// this is it, just do @cImport instead of @import
const c = @cImport({
@cInclude("unistd.h");
});pub fn main() void {
// as a bonus the C functions are already namespaced too
const res = c.write(2, "Hello C from Zig!", 17);
}Jeremy Falcon
You almost got me ready to learn it. When it will run on ARM, I will definitely consider.
A home without books is a body without soul. Marcus Tullius Cicero PartsBin an Electronics Part Organizer - Release Version 1.4.0 (Many new features) JaxCoder.com Latest Article: EventAggregator
-
You almost got me ready to learn it. When it will run on ARM, I will definitely consider.
A home without books is a body without soul. Marcus Tullius Cicero PartsBin an Electronics Part Organizer - Release Version 1.4.0 (Many new features) JaxCoder.com Latest Article: EventAggregator
Mike Hankey wrote:
You almost got me ready to learn it.
You're in luck, it already supports ARM cross compilation. [Zig cross compilation](https://zig.guide/build-system/cross-compilation/) I haven't tried it for ARM yet, but that's what the site says. The main reason I'm learning it, is it's meant to be a direct successor to C... not C++ but C. You have projects like D or even Rust that creep into the overly complicated theory territory. Zig is like, nah screw that, this be C 2.0. Don't get me wrong, you can kinda mimic interfaces in Zig as an example, but it just feels way more like C than most other languages out there. But, with some newer features that came about since the 70s... like a standard package manager that every other language besides C has standardized by now and built in unit testing. Which IMO is awesome. It's still a young language (only started 8 years ago), but they recently got 21 million in funding for their series B. So, it's gonna continue to mature and evolve. Probably take several years to finally get to 1.0 though, so just be aware. The current release version is 0.13.0 and it'll be a bit before 0.14.0 is out. But, still... gotta start somewhere.
Jeremy Falcon
-
You almost got me ready to learn it. When it will run on ARM, I will definitely consider.
A home without books is a body without soul. Marcus Tullius Cicero PartsBin an Electronics Part Organizer - Release Version 1.4.0 (Many new features) JaxCoder.com Latest Article: EventAggregator
Oh, I should say there aren't any beginner books on it yet. It's all still so new. There are some scam books that are AI generated and wrong on Amazon, but not legit ones. [One](https://kristoff.it/blog/note-about-zig-books/) is being worked on though, and I'm sure others will arrive in the future. So, for right now, it's gonna be online resources like [ziglings](https://codeberg.org/ziglings/exercises/src/branch/main/exercises), ziglang.org, zig.guide, reddit, Google, etc. Here's a list of projects using Zig, including editor plugins, etc. [Zig Learning Guide & Project Lists](https://github.com/C-BJ/awesome-zig) Reminds me of getting in on Linux during the early days though. Kinda exciting.
Jeremy Falcon
-
Mike Hankey wrote:
You almost got me ready to learn it.
You're in luck, it already supports ARM cross compilation. [Zig cross compilation](https://zig.guide/build-system/cross-compilation/) I haven't tried it for ARM yet, but that's what the site says. The main reason I'm learning it, is it's meant to be a direct successor to C... not C++ but C. You have projects like D or even Rust that creep into the overly complicated theory territory. Zig is like, nah screw that, this be C 2.0. Don't get me wrong, you can kinda mimic interfaces in Zig as an example, but it just feels way more like C than most other languages out there. But, with some newer features that came about since the 70s... like a standard package manager that every other language besides C has standardized by now and built in unit testing. Which IMO is awesome. It's still a young language (only started 8 years ago), but they recently got 21 million in funding for their series B. So, it's gonna continue to mature and evolve. Probably take several years to finally get to 1.0 though, so just be aware. The current release version is 0.13.0 and it'll be a bit before 0.14.0 is out. But, still... gotta start somewhere.
Jeremy Falcon
Damn another project. :)
A home without books is a body without soul. Marcus Tullius Cicero PartsBin an Electronics Part Organizer - Release Version 1.4.0 (Many new features) JaxCoder.com Latest Article: EventAggregator
-
Yes, it's Zig. Forgive me because I'm becoming a wordle post. :laugh: But, I just gotta say, this is how extremely easy it is to use C code in Zig...
// this is it, just do @cImport instead of @import
const c = @cImport({
@cInclude("unistd.h");
});pub fn main() void {
// as a bonus the C functions are already namespaced too
const res = c.write(2, "Hello C from Zig!", 17);
}Jeremy Falcon
Sooo... it really just wants to be C when it grows up?
-
Sooo... it really just wants to be C when it grows up?
I mean I know this is a joke... so the obligatory har har har... har har har. :laugh: :laugh: :laugh: Buuutttt, and I know I'm sounding like a fanboi, but it's doing things that apparently the peeps behind C are too old to care about. Like, I mean, Zig sounds silly in name but I'm sure C is ran by grandpas still using an outhouse. Let me just give you a simple example here, every other modern language has a concept of lambda type expressions (using C# nomenclature), but not C. Now, Zig doesn't do that 1 for 1, but let me just show you with code.
for (0..10) |i| {
// variable 'i' will have each value 0 to 9
}Of course you can do that in C by manually declaring crap, but it's so much more verbose and a waste of typing. Or what about a while block that supports a counter.
while (n <= 20) : (n += 1) {
// stuff
}Or and this is where things get crazy, being able to name blocks and break out of them.
namedBlock: {
// do stuff
break :namedBlock 42; // 42 is a return value if you want to assign this block to variable
// no stuff done because of break
}I could go on, but I'd be writing a book here. But stuff like `comptime` makes C macros look like a joke. I say this as a dude who loves C. I'm not a hater; I'm just a realist. I mean like it or not man, history has shown us that things die out if they don't evolve. Nobody is speaking much Latin these days despite the fact it used to dominate the world. We're just too close to C to realize it's gotten very little love for a long time. Been 50 years man. That's half a century. The world has moved on.
Jeremy Falcon
-
Yes, it's Zig. Forgive me because I'm becoming a wordle post. :laugh: But, I just gotta say, this is how extremely easy it is to use C code in Zig...
// this is it, just do @cImport instead of @import
const c = @cImport({
@cInclude("unistd.h");
});pub fn main() void {
// as a bonus the C functions are already namespaced too
const res = c.write(2, "Hello C from Zig!", 17);
}Jeremy Falcon
Jeremy Falcon wrote:
Forgive me because I'm becoming a wordle post.
Could be worse, could be a CCC post.
Wrong is evil and must be defeated. - Jeff Ello
-
I mean I know this is a joke... so the obligatory har har har... har har har. :laugh: :laugh: :laugh: Buuutttt, and I know I'm sounding like a fanboi, but it's doing things that apparently the peeps behind C are too old to care about. Like, I mean, Zig sounds silly in name but I'm sure C is ran by grandpas still using an outhouse. Let me just give you a simple example here, every other modern language has a concept of lambda type expressions (using C# nomenclature), but not C. Now, Zig doesn't do that 1 for 1, but let me just show you with code.
for (0..10) |i| {
// variable 'i' will have each value 0 to 9
}Of course you can do that in C by manually declaring crap, but it's so much more verbose and a waste of typing. Or what about a while block that supports a counter.
while (n <= 20) : (n += 1) {
// stuff
}Or and this is where things get crazy, being able to name blocks and break out of them.
namedBlock: {
// do stuff
break :namedBlock 42; // 42 is a return value if you want to assign this block to variable
// no stuff done because of break
}I could go on, but I'd be writing a book here. But stuff like `comptime` makes C macros look like a joke. I say this as a dude who loves C. I'm not a hater; I'm just a realist. I mean like it or not man, history has shown us that things die out if they don't evolve. Nobody is speaking much Latin these days despite the fact it used to dominate the world. We're just too close to C to realize it's gotten very little love for a long time. Been 50 years man. That's half a century. The world has moved on.
Jeremy Falcon
"the peeps behind C are too old to care about" sigh... that's racist. lol. Not really, but I'm trying to fix something that works in the real world. I already have some thoughts about your posts.
Charlie Gilley “They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759 Has never been more appropriate.
-
I mean I know this is a joke... so the obligatory har har har... har har har. :laugh: :laugh: :laugh: Buuutttt, and I know I'm sounding like a fanboi, but it's doing things that apparently the peeps behind C are too old to care about. Like, I mean, Zig sounds silly in name but I'm sure C is ran by grandpas still using an outhouse. Let me just give you a simple example here, every other modern language has a concept of lambda type expressions (using C# nomenclature), but not C. Now, Zig doesn't do that 1 for 1, but let me just show you with code.
for (0..10) |i| {
// variable 'i' will have each value 0 to 9
}Of course you can do that in C by manually declaring crap, but it's so much more verbose and a waste of typing. Or what about a while block that supports a counter.
while (n <= 20) : (n += 1) {
// stuff
}Or and this is where things get crazy, being able to name blocks and break out of them.
namedBlock: {
// do stuff
break :namedBlock 42; // 42 is a return value if you want to assign this block to variable
// no stuff done because of break
}I could go on, but I'd be writing a book here. But stuff like `comptime` makes C macros look like a joke. I say this as a dude who loves C. I'm not a hater; I'm just a realist. I mean like it or not man, history has shown us that things die out if they don't evolve. Nobody is speaking much Latin these days despite the fact it used to dominate the world. We're just too close to C to realize it's gotten very little love for a long time. Been 50 years man. That's half a century. The world has moved on.
Jeremy Falcon
"I'm sure C is ran by grandpas still using an outhouse." Okay Mr. Falcon, you're getting edgy here and somewhat triggered me. I would point out that there is beaucoup code out there happily running all written in C. The good news is that we - us grandpas and great grandpas - have a STABLE compiler. It's only worked for decades. But lets take a look at your code examples. Now, I don't know anything about "zig" other than it's another open source compiler to continue to confuse crap... so fair disclaimer. "pub fn main() void {" Great, so for decades the suggestion has been to make your variable names readable in whatever language is native to you. Looks like zig has reduced public to pub and function to fn. Not a good start. "const res = c.write(2, "Hello C from Zig!", 17);" does not impress me. Why? I'm supposing c.write assigns the output to res. - Is res a dnamically allocated variable? String? Buffer of x bytes? Again, I don't know zig, but I have further issues. - What does the 2 do? - 17. Hmm, why not let the compiler handle the null terminated string? If I change the string, boom, the # is wrong. Fights on :) Everything I just posted is meant in technical respect.
Charlie Gilley “They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759 Has never been more appropriate.
-
"the peeps behind C are too old to care about" sigh... that's racist. lol. Not really, but I'm trying to fix something that works in the real world. I already have some thoughts about your posts.
Charlie Gilley “They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759 Has never been more appropriate.
charlieg wrote:
sigh... that's racist. lol
Touché, buddy. :laugh: :laugh:
Jeremy Falcon
-
"I'm sure C is ran by grandpas still using an outhouse." Okay Mr. Falcon, you're getting edgy here and somewhat triggered me. I would point out that there is beaucoup code out there happily running all written in C. The good news is that we - us grandpas and great grandpas - have a STABLE compiler. It's only worked for decades. But lets take a look at your code examples. Now, I don't know anything about "zig" other than it's another open source compiler to continue to confuse crap... so fair disclaimer. "pub fn main() void {" Great, so for decades the suggestion has been to make your variable names readable in whatever language is native to you. Looks like zig has reduced public to pub and function to fn. Not a good start. "const res = c.write(2, "Hello C from Zig!", 17);" does not impress me. Why? I'm supposing c.write assigns the output to res. - Is res a dnamically allocated variable? String? Buffer of x bytes? Again, I don't know zig, but I have further issues. - What does the 2 do? - 17. Hmm, why not let the compiler handle the null terminated string? If I change the string, boom, the # is wrong. Fights on :) Everything I just posted is meant in technical respect.
Charlie Gilley “They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759 Has never been more appropriate.
charlieg wrote:
The good news is that we - us grandpas and great grandpas - have a STABLE compiler.
I should say, C is and will always be my favorite language. It's served me well over the years and will always have a special place in my heart. I promise I'm not one of these zealot hater types. But, ya know... I will joke about it. :-D
charlieg wrote:
Great, so for decades the suggestion has been to make your variable names readable in whatever language is native to you. Looks like zig has reduced public to pub and function to fn. Not a good start.
I'm a realist, so there are things in Zig I'm not crazy about. IMO they should've made the syntax a bit more C-like to be C 2.0. But, the good outweighs the bad. So, I overlook stuff like `fn` instead of `function`. I totally agree with the point that we should be moving away from too many abbreviations though, 100%.
charlieg wrote:
Is res a dnamically allocated variable? String? Buffer of x bytes? Again, I don't know zig, but I have further issues.
It's the same as using that C function in C. No different. Zig just allows you use that C function so you don't have to abandon decades of code on the C side. So, [write](https://pubs.opengroup.org/onlinepubs/007908799/xsh/write.html) would return the number of bytes.
charlieg wrote:
- 17. Hmm, why not let the compiler handle the null terminated string? If I change the string, boom, the # is wrong.
Actually, the compiler does handle that. I was just being lazy and writing a simple example.
charlieg wrote:
Fights on :) Everything I just posted is meant in technical respect.
Fair enough. :laugh: Just know I love C. I do wish it evolved a bit more in the past 50 years though. Adding new features doesn't mean you have to break compatibility.
Jeremy Falcon