"Multi pointers" are now "many pointers"

TypeInfo.Pointer.Size says "many", so there we are!
This commit is contained in:
Dave Gauer 2021-03-07 10:08:07 -05:00
parent 4a421cca28
commit 784b66ffcf
5 changed files with 11 additions and 11 deletions

View file

@ -129,7 +129,7 @@ Planned exercises:
* [x] Optionals * [x] Optionals
* [x] Struct methods * [x] Struct methods
* [x] Slices * [x] Slices
* [x] Multi pointers * [x] Many pointers
* [ ] Unions * [ ] Unions
* [ ] Numeric types (integers, floats) * [ ] Numeric types (integers, floats)
* [ ] Labelled blocks and loops * [ ] Labelled blocks and loops

View file

@ -277,7 +277,7 @@ const exercises = [_]Exercise{
.output = "'all your base are belong to us.' 'for great justice.'", .output = "'all your base are belong to us.' 'for great justice.'",
}, },
.{ .{
.main_file = "54_multipointers.zig", .main_file = "54_manypointers.zig",
.output = "Memory is a resource.", .output = "Memory is a resource.",
}, },
}; };

View file

@ -18,19 +18,19 @@ pub fn main() void {
// //
// const zen12: []const u8 = "..."; // const zen12: []const u8 = "...";
// //
// Now let's turn this into a "multi pointer": // Now let's turn this into a "many pointer":
const zen_multiptr: [*]const u8 = zen12; const zen_manyptr: [*]const u8 = zen12;
// It's okay to access zen_multiptr just like an array or slice as // It's okay to access zen_manyptr just like an array or slice as
// long as you keep track of the length yourself! // long as you keep track of the length yourself!
// //
// A "string" in Zig is a pointer to an array of const u8 values // A "string" in Zig is a pointer to an array of const u8 values
// or a slice of const u8 values, into one, as we saw above). So, // or a slice of const u8 values, into one, as we saw above). So,
// we could treat a "multi pointer" of const u8 a string as long // we could treat a "many pointer" of const u8 a string as long
// as we can CONVERT IT TO A SLICE. (Hint: we do know the length!) // as we can CONVERT IT TO A SLICE. (Hint: we do know the length!)
// //
// Please fix this line so the print below statement can print it: // Please fix this line so the print below statement can print it:
const zen12_string: []const u8 = zen_multiptr; const zen12_string: []const u8 = zen_manyptr;
// Here's the moment of truth! // Here's the moment of truth!
std.debug.print("{s}\n", .{zen12_string}); std.debug.print("{s}\n", .{zen12_string});

View file

@ -0,0 +1,4 @@
33c33
< const zen12_string: []const u8 = zen_manyptr;
---
> const zen12_string: []const u8 = zen_manyptr[0..21];

View file

@ -1,4 +0,0 @@
33c33
< const zen12_string: []const u8 = zen_multiptr;
---
> const zen12_string: []const u8 = zen_multiptr[0..21];