hachyderm.io is one of the many independent Mastodon servers you can use to participate in the fediverse.
Hachyderm is a safe space, LGBTQIA+ and BLM, primarily comprised of tech industry professionals world wide. Note that many non-user account types have restrictions - please see our About page.

Administered by:

Server stats:

9.5K
active users

b4ux1t3 :trek_ds9_sisko:#1️⃣

So. . .if I print a pointer for an array in , I can see the whole array. If I print an individual value, I see the address (And datatype, which is cool).

Do arrays work significantly differently in zig from C? Like, i the pointer to the array the same as the pointer to the value, but the compiler is injecting some magic into the format string?

@b4ux1t3 The types of these things are different enough to confuse when you’re first learning, but so much clearer to use after that point:

myNums is an array: a set of bytes (w/ comptime length)
&myNums or myNums[0..] is a slice, or a reference (w/ runtime length)
myNums[0] is the value at index 0
&myNums[0] is a pointer to the value at index 0

“a” here isn’t quite what I said though, your type specifically asks for the address of a 4-byte array so that’s what you got, not the slice []u8.

@b4ux1t3

Once you get a pointer to a u8, like “b”, you can get the value using “b.*”.