summaryrefslogtreecommitdiff
path: root/exercises/065_builtins2.zig
diff options
context:
space:
mode:
authorChris Boesch <chrboesch@noreply.codeberg.org>2026-06-03 18:37:25 +0200
committerChris Boesch <chrboesch@noreply.codeberg.org>2026-06-03 18:37:25 +0200
commitb7ff71cb9e7fba6365e78f00bd75e0d5d507cbfc (patch)
tree6c3f664ff0a900e0d1132f54a1c0410baf389e33 /exercises/065_builtins2.zig
parentbeeca8d510891a272868f447e8193b0fcee7e2fc (diff)
parenta403436fe8ca2ce7fc53e81365f91ecc6051ef97 (diff)
Merge pull request 'Fix exercises 65, 71, 82 due to the build system update' (#443) from mark2185/exercises:fix-build-update into main
Reviewed-on: https://codeberg.org/ziglings/exercises/pulls/443
Diffstat (limited to 'exercises/065_builtins2.zig')
-rw-r--r--exercises/065_builtins2.zig33
1 files changed, 11 insertions, 22 deletions
diff --git a/exercises/065_builtins2.zig b/exercises/065_builtins2.zig
index eb8f3aa..78cd23b 100644
--- a/exercises/065_builtins2.zig
+++ b/exercises/065_builtins2.zig
@@ -93,36 +93,25 @@ pub fn main() void {
print("He has room in his heart for:", .{});
- // A StructFields array
- const fields = @typeInfo(Narcissus).@"struct".fields;
+ // `field_names` is a slice of strings and it holds the names of the struct's fields
+ // `field_types` is a slice of strings and it holds the types of the struct's fields,
+ // it is guaranteed to be the same length as `field_names`
+ const field_names = @typeInfo(Narcissus).@"struct".field_names;
+ const field_types = @typeInfo(Narcissus).@"struct".field_types;
- // 'fields' is a slice of StructFields. Here's the declaration:
- //
- // pub const StructField = struct {
- // name: [:0]const u8, // Don't worry about `:0` yet!
- // type: type,
- // default_value_ptr: ?*const anyopaque,
- // is_comptime: bool,
- // alignment: comptime_int,
- //
- // defaultValue() ?sf.type // Function that loads the
- // // field's default value from
- // // `default_value_ptr`
- // };
- //
// Please complete these 'if' statements so that the field
// name will not be printed if the field is of type 'void'
// (which is a zero-bit type that takes up no space at all!):
- if (fields[0].??? != void) {
- print(" {s}", .{fields[0].name});
+ if (field_???[???] != void) {
+ print(" {s}", .{field_???[???]});
}
- if (fields[1].??? != void) {
- print(" {s}", .{fields[1].name});
+ if (field_???[???] != void) {
+ print(" {s}", .{field_???[???]});
}
- if (fields[2].??? != void) {
- print(" {s}", .{fields[2].name});
+ if (field_???[???] != void) {
+ print(" {s}", .{field_???[???]});
}
// Yuck, look at all that repeated code above! I don't know