Skip to content

Commit

Permalink
Merge pull request #51 from pedropark99/revision-2
Browse files Browse the repository at this point in the history
Add a revision of Chapter 2
  • Loading branch information
pedropark99 authored Oct 2, 2024
2 parents afebb2e + 2610591 commit 222ef40
Show file tree
Hide file tree
Showing 25 changed files with 686 additions and 495 deletions.
421 changes: 269 additions & 152 deletions Chapters/03-structs.qmd

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Chapters/09-error-handling.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ if (add_tasks_to_queue(&queue, tasks)) |_| {
```


### The `errdefer` keyword
### The `errdefer` keyword {#sec-errdefer2}

A commom pattern in C programs in general, is to clean resources when an error occurs during
the execution of the program. In other words, one commom way to handle errors, is to perform
Expand Down
14 changes: 14 additions & 0 deletions ZigExamples/zig-basics/defer.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// This program demonstrates that an expression registered
// with `defer` is executed no matter how the code exits the current scope
// (i.e. if it exits with an error, or, exits from a return statement, a break statement, etc.)
const std = @import("std");
fn foo() !void {
return error.Test;
}

pub fn main() !void {
var i: usize = 1;
errdefer std.debug.print("Value of i: {d}\n", .{i});
defer i = 2;
try foo();
}
8 changes: 3 additions & 5 deletions _freeze/Chapters/03-structs/execute-results/html.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions _freeze/Chapters/09-error-handling/execute-results/html.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/Chapters/01-base64.html
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../Chapters/03-structs.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">2</span>&nbsp; <span class="chapter-title">Structs, Modules and Control Flow</span></span></a>
<span class="menu-text"><span class="chapter-number">2</span>&nbsp; <span class="chapter-title">Control flow, structs, modules and types</span></span></a>
</div>
</li>
<li class="sidebar-item">
Expand Down
6 changes: 3 additions & 3 deletions docs/Chapters/01-memory.html
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../Chapters/03-structs.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">2</span>&nbsp; <span class="chapter-title">Structs, Modules and Control Flow</span></span></a>
<span class="menu-text"><span class="chapter-number">2</span>&nbsp; <span class="chapter-title">Control flow, structs, modules and types</span></span></a>
</div>
</li>
<li class="sidebar-item">
Expand Down Expand Up @@ -1256,8 +1256,8 @@ <h3 data-number="3.2.9" class="anchored" data-anchor-id="the-create-and-destroy-
</script>
<nav class="page-navigation">
<div class="nav-page nav-page-previous">
<a href="../Chapters/03-structs.html" class="pagination-link" aria-label="Structs, Modules and Control Flow">
<i class="bi bi-arrow-left-short"></i> <span class="nav-page-text"><span class="chapter-number">2</span>&nbsp; <span class="chapter-title">Structs, Modules and Control Flow</span></span>
<a href="../Chapters/03-structs.html" class="pagination-link" aria-label="Control flow, structs, modules and types">
<i class="bi bi-arrow-left-short"></i> <span class="nav-page-text"><span class="chapter-number">2</span>&nbsp; <span class="chapter-title">Control flow, structs, modules and types</span></span>
</a>
</div>
<div class="nav-page nav-page-next">
Expand Down
6 changes: 3 additions & 3 deletions docs/Chapters/01-zig-weird.html
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../Chapters/03-structs.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">2</span>&nbsp; <span class="chapter-title">Structs, Modules and Control Flow</span></span></a>
<span class="menu-text"><span class="chapter-number">2</span>&nbsp; <span class="chapter-title">Control flow, structs, modules and types</span></span></a>
</div>
</li>
<li class="sidebar-item">
Expand Down Expand Up @@ -1621,8 +1621,8 @@ <h2 data-number="1.10" class="anchored" data-anchor-id="other-parts-of-zig"><spa
</a>
</div>
<div class="nav-page nav-page-next">
<a href="../Chapters/03-structs.html" class="pagination-link" aria-label="Structs, Modules and Control Flow">
<span class="nav-page-text"><span class="chapter-number">2</span>&nbsp; <span class="chapter-title">Structs, Modules and Control Flow</span></span> <i class="bi bi-arrow-right-short"></i>
<a href="../Chapters/03-structs.html" class="pagination-link" aria-label="Control flow, structs, modules and types">
<span class="nav-page-text"><span class="chapter-number">2</span>&nbsp; <span class="chapter-title">Control flow, structs, modules and types</span></span> <i class="bi bi-arrow-right-short"></i>
</a>
</div>
</nav>
Expand Down
2 changes: 1 addition & 1 deletion docs/Chapters/02-debugging.html
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../Chapters/03-structs.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">2</span>&nbsp; <span class="chapter-title">Structs, Modules and Control Flow</span></span></a>
<span class="menu-text"><span class="chapter-number">2</span>&nbsp; <span class="chapter-title">Control flow, structs, modules and types</span></span></a>
</div>
</li>
<li class="sidebar-item">
Expand Down
Loading

0 comments on commit 222ef40

Please sign in to comment.