Skip to content

Commit a0a9920

Browse files
committed
Revised exercises due to the changes of Zig version 0.11.0-dev.3853
1 parent a57926b commit a0a9920

11 files changed

+16
-13
lines changed

README.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Verify the installation and build number of `zig` like so:
4545

4646
```
4747
$ zig version
48-
0.11.0-dev.3747+xxxxxxxxx
48+
0.11.0-dev.3853+xxxxxxxxx
4949
```
5050

5151
Clone this repository with Git:
@@ -90,7 +90,8 @@ that if you update one, you may need to also update the other.
9090
### Version Changes
9191

9292
Version-0.11.0-dev.3747+7b5bd3a93
93-
* *2023-05-25* zig 0.11.0-dev.3747 - `@enumToInt` is now `@intFromEnum` and `@intToFloat` is now `@floatFromInt`
93+
* *2023-06-26* zig 0.11.0-dev.3853 - removal of destination type from all cast builtins
94+
* *2023-06-20* zig 0.11.0-dev.3747 - `@enumToInt` is now `@intFromEnum` and `@intToFloat` is now `@floatFromInt`
9495
* *2023-05-25* zig 0.11.0-dev.3295 - `std.debug.TTY` is now `std.io.tty`
9596
* *2023-04-30* zig 0.11.0-dev.2704 - use of the new `std.Build.ExecutableOptions.link_libc` field
9697
* *2023-04-12* zig 0.11.0-dev.2560 - changes in `std.Build` - remove run() and install()
@@ -211,7 +212,7 @@ Zig Standard Library
211212

212213
* [X] String formatting
213214
* [X] Testing
214-
* [ ] Tokenization
215+
* [X] Tokenization
215216

216217
## Contributing
217218

build.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ pub fn build(b: *Build) !void {
104104
const WINAPI = std.os.windows.WINAPI;
105105
const DWORD = std.os.windows.DWORD;
106106
const ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x0004;
107-
const STD_ERROR_HANDLE = @bitCast(DWORD, @as(i32, -12));
107+
const STD_ERROR_HANDLE: DWORD = @bitCast(@as(i32, -12));
108108
extern "kernel32" fn GetStdHandle(id: DWORD) callconv(WINAPI) ?*anyopaque;
109109
extern "kernel32" fn GetConsoleMode(console: ?*anyopaque, out_mode: *DWORD) callconv(WINAPI) u32;
110110
extern "kernel32" fn SetConsoleMode(console: ?*anyopaque, mode: DWORD) callconv(WINAPI) u32;

exercises/016_for2.zig

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ pub fn main() void {
2929
// Note that we convert the usize i to a u32 with
3030
// @intCast(), a builtin function just like @import().
3131
// We'll learn about these properly in a later exercise.
32-
const place_value = std.math.pow(u32, 2, @intCast(u32, i));
32+
const i_u32: u32 = @intCast(i);
33+
const place_value = std.math.pow(u32, 2, i_u32);
3334
value += place_value * bit;
3435
}
3536

exercises/058_quiz7.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ fn printTrip(trip: []?TripItem) void {
429429
// We convert the usize length to a u8 with @intCast(), a
430430
// builtin function just like @import(). We'll learn about
431431
// these properly in a later exercise.
432-
var i: u8 = @intCast(u8, trip.len);
432+
var i: u8 = @intCast(trip.len);
433433

434434
while (i > 0) {
435435
i -= 1;

exercises/069_comptime4.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ fn makeSequence(comptime T: type, ??? size: usize) [???]T {
4747
var i: usize = 0;
4848

4949
while (i < size) : (i += 1) {
50-
sequence[i] = @intCast(T, i) + 1;
50+
sequence[i] = @as(T, @intCast(i)) + 1;
5151
}
5252

5353
return sequence;

exercises/075_quiz8.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ pub fn main() void {
204204
}
205205

206206
fn printTrip(trip: []?TripItem) void {
207-
var i: u8 = @intCast(u8, trip.len);
207+
var i: u8 = @intCast(trip.len);
208208

209209
while (i > 0) {
210210
i -= 1;

exercises/096_memory_allocation.zig

+2-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ fn runningAverage(arr: []const f64, avg: []f64) void {
4545

4646
for (0.., arr) |index, val| {
4747
sum += val;
48-
avg[index] = sum / @floatFromInt(f64, index + 1);
48+
const f_index: f64 = @floatFromInt(index + 1);
49+
avg[index] = sum / f_index;
4950
}
5051
}
5152

exercises/098_bit_manipulation2.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ fn isPangram(str: []const u8) bool {
5353
// and are numbered sequentially, we simply subtract the
5454
// first letter (in this case the 'a') from the character
5555
// found, and thus get the position of the desired bit
56-
bits |= @as(u32, 1) << @truncate(u5, ascii.toLower(c) - 'a');
56+
bits |= @as(u32, 1) << @truncate(ascii.toLower(c) - 'a');
5757
}
5858
}
5959
// last we return the comparison if all 26 bits are set,

patches/patches/078_sentinels3.patch

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
24c24
22
< const printable: [*:0]const u8 = ???;
33
---
4-
> const printable: [*:0]const u8 = @ptrCast([*:0]const u8, data);
4+
> const printable: [*:0]const u8 = @ptrCast(data);
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
66c66
1+
67c67
22
< var avg: []f64 = ???;
33
---
44
> var avg: []f64 = try allocator.alloc(f64, arr.len);

src/compat.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const print = if (@hasDecl(debug, "print")) debug.print else debug.warn;
1515
// When changing this version, be sure to also update README.md in two places:
1616
// 1) Getting Started
1717
// 2) Version Changes
18-
const needed_version_str = "0.11.0-dev.3747";
18+
const needed_version_str = "0.11.0-dev.3853";
1919

2020
fn isCompatible() bool {
2121
if (!@hasDecl(builtin, "zig_version") or !@hasDecl(std, "SemanticVersion")) {

0 commit comments

Comments
 (0)