1
I got got (lemmy.world)
submitted 1 month ago by to c/zig@programming.dev
 
 

I'm recovering from getting my wisdom teeth removed and decided to finally learn Zig to kill some time. Started up Ziglings and everything was completely smooth until the Exercise that had Error Unions. Couldn't figure out for the life of me why I was getting an Error for doing exactly what the exercise taught me to do though!!

var my_number: u8|MyNumberError = 5;

I tried reading the error messages, checked if maybe my zls version was set to something wrong, checked the ziglang changelog if maybe the syntax changed between v16 and v17, checked the Issues tabs on the Ziglings git to see if anyone else had this issue, and then re-checked the zig documentation on my phone just to realize:

The Error union type is supposed to be defined with an exclamation mark (!) instead of a pipe (|), I was just misreading it because I'm not wearing my glasses! And I guess I'm used to seeing pipes used in types because it's common in TypeScript haha

2
 
 

I'm currently learning the language, and I was wondering about this design quirk.

Basically, if we have a variable x which is a pointer, we use x.* to get the value. This is much better than using * as a prefix, since the * might need to be applied to anything in the chain for complex access. I see the usecase.

For example something like

(*(*pointer_to_struct).struct_field_ptr).struct_field

is much more clearly written as

pointer_to_struct.*.struct_field_ptr.*.struct_field

But then it feels really inconsistent that we don't do the same for taking a reference with &. Sure, we only ever take one reference of the entire value, so we don't have the same problem as above, but:

We still have the issue that the & is not next to the value being dereferenced:

&some_ptr.*.some_array_struct_field[5].target

this takes the address of the target struct field, which is on the opposite side of the expression.

It also just feels inconsistent.

Additionally, I think the type declaration for a pointer should be &u8, not *u8. Since the & character is semantically equivalent to "address of", and * is more like "value at address".

Thoughts?

3
submitted 3 months ago by to c/zig@programming.dev
4
5
Lessons from Zig (www.vinniefalco.com)
submitted 5 months ago by to c/zig@programming.dev
6
 
 

Today participating at the Zig Day event in Nuremberg: https://zig.day/europe/nuremberg/

#zig @zig https://ziglang.org/

7
8
9
submitted 6 months ago by to c/zig@programming.dev
10
11
12
13
 
 

I need to boast a bit and ask for "code review". I'm sorry if this doesn't constitute a good post.

I browse local communities more often than I should for my mental health.

I was checking out https://nim-lang.org/ and when I googled it one of the links was to rosettacode.org and I decided to check out the implementation of 2048.

I noticed that zig's implementation was a non-working auto translation of rust's, so I decided to rewrite it.

My repo: https://codeberg.org/Vulwsztyn/2048_zig

With the reader, writer, and arraylist api changes in 0.15 most of the sources were usless and if I hadn't found https://github.com/xyaman/mibu I guess I would have surrendered.

Feel free to roast the hell out of my code.

14
15
16
Zig 0.15.1 Released (ziglang.org)
submitted 11 months ago by to c/zig@programming.dev
 
 

Debug compilation is 5 times faster with Zig's x86 Backend selected by default; the work-in-progress aarch64 Backend hot on its heels. Meanwhile, the Writergate scandal, along with a slew of Language Changes and Standard Library cuts, rocks the boat with tidal waves of breaking API changes; the harbinger of async/await resurrection; the last bastion defending language stabilization.

17
18
19
Zig defer Patterns (matklad.github.io)
submitted 2 years ago by to c/zig@programming.dev
20
QOI Encoding in Zig (giannirosato.com)
submitted 2 years ago by to c/zig@programming.dev
 
 

cross-posted from: https://lemmy.ml/post/13183095

21
22
23
24
25
view more: next ›