11# Understanding How Zig and C Interact
22
3- My journey to understanding how Zig interacts with C and how I, someone not
4- well-versed in C, can leverage the power of third-party C libraries.
3+ A journey to understanding how Zig interacts with C and how someone not
4+ well-versed in C can leverage the power of third-party C libraries.
55
66## What This Doesn't Cover
77
@@ -71,7 +71,7 @@ int sub(int a, int b) {
7171
7272` ` `
7373
74- Next I created a simple application to utilize this library.
74+ Next we create a simple application to utilize this library.
7575
7676[` c_app.c` ](src/c_app.c)
7777` ` ` c
@@ -197,7 +197,7 @@ Same results as compiling with `zig cc`! Very cool. Let's move on to using a bit
197197
198198### Create a Zig application that links to the C library
199199
200- Basically, I want to recreate my `c_app.c` in Zig. In this case, this is trivial.
200+ Basically, we want to recreate `c_app.c` in Zig. In this case, this is trivial.
201201
202202[`zig_app.zig`](src/zig_app.zig)
203203```c
@@ -258,7 +258,7 @@ using a C library (when source code is available).
258258
259259### Using Zig to build a C Library
260260
261- Up until now, I ' ve been utilizing the C source code, since it' s available to us,
261+ Up until now, we ' ve been utilizing the C source code, since it' s available to us,
262262but this is not always the case. Sometimes we may have a static or shared library
263263that we need to link against, rather than compiling the source code ourselves.
264264
@@ -305,7 +305,7 @@ have a Zig interface between our application code and our C code. This allows us
305305to handle errors in a Zig fashion and pass proper types to the C code while
306306exposing them to the application code.
307307
308- For this I ' ll create a new Zig file, `zmath_ext.zig`
308+ For this we ' ll create a new Zig file, `zmath_ext.zig`
309309
310310[`zmath_ext.zig`](src/zmath_ext.zig)
311311```c
@@ -343,7 +343,7 @@ the C function's parameters. You'll also notice the return type contains `!`,
343343meaning these functions will now return errors. This means within our
344344application, we' ll need to call the function with `try`.
345345
346- I ' ll create a new zig file for trying out the wrapper functions, called
346+ We ' ll create a new zig file for trying out the wrapper functions, called
347347` zig_c_wrapper.zig` . This is mostly to distinguish between our previous examples,
348348but this is just showing we no longer use `@cImport ()` directly, and instead
349349utilize ` zmath.zig` (our wrapper functions), to interact with the C code.
@@ -395,13 +395,13 @@ a path (using `addObjectFile()`). If you build from source, use `addObject(*Comp
395395instead and pass in the proper object. This is because Zig will compile faster
396396than your OS can save the library file, causing the build to fail because the
397397library file could not be found during the build time of this object (at least
398- when using `dependsOn ()` , like I do in my main [` build.zig` ](build.zig) file
398+ when using `dependsOn ()` , like we do in the main [` build.zig` ](build.zig) file
399399for this repo).
400400
401401
402402# # Side Quests
403403
404- Some extra thoughts I have about integrating Zig and C together .
404+ Some extra thoughts about working with Zig and intergrating/interacting with C .
405405
406406# ## Testing C code in Zig
407407
@@ -427,7 +427,7 @@ test "zmath.sub() works" {
427427` ` `
428428_Strive to write good tests, this is just a proof of concept._
429429
430- ` build.zig`
430+ [ ` build.zig` ](build_test_zmath.zig)
431431` ` ` c
432432const std = @import(" std" );
433433
0 commit comments