@@ -311,14 +311,14 @@ For this we'll create a new Zig file, `zmath_ext.zig`
311311```c
312312const zmath_h = @cImport(@cInclude("zmath.h"));
313313
314- pub extern fn add(a: c_int, b: c_int) c_int;
315- pub extern fn sub(a: c_int, b: c_int) c_int;
314+ pub extern fn add(a: c_int, b: c_int) callconv(.C) c_int;
315+ pub extern fn sub(a: c_int, b: c_int) callconv(.C) c_int;
316316```
317317
318- This file is a declaration of external functions we wish to use Zig. We' ll next
319- create a ` zmath.zig` , in which we will create Zig functions that will expose
320- Zig data types through our API and cast the parameters to their corresponding C
321- data types before calling the C functions.
318+ This file is a declaration of external functions we wish to use in Zig. We' ll
319+ next create a ` zmath.zig` , in which we will create Zig functions that will
320+ expose Zig data types through our API and cast the parameters to their
321+ corresponding C data types before calling the C functions.
322322
323323[` zmath.zig` ](src/zmath.zig)
324324` ` ` c
@@ -338,7 +338,7 @@ pub fn sub(a: i32, b: i32) !i32 {
338338` ` `
339339
340340As you can see, we translate the C types to Zig specific types for use in Zig
341- applications. WE cast our input parameters to their C equivalent (` c_int` ) for
341+ applications. We cast our input parameters to their C equivalent (` c_int` ) for
342342the 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`.
@@ -457,9 +457,10 @@ pub fn build(b: *std.Build) void {
457457- https://mtlynch.io/notes/zig-call-c-simple/
458458What initially made me want to tackle this subject, this article is a great
459459starting point for understanding C and Zig.
460-
461460- [Wikipedia article for " Shared Library" ](https://en.wikipedia.org/wiki/Shared_library)
462461- [Wikipedia article for " Static Library" ](https://en.wikipedia.org/wiki/Static_library)
462+ - [Discussion about this repository on Ziggit](https://ziggit.dev/t/blog-understanding-how-zig-and-c-interact/6733/7)
463+
463464
464465
465466# # Thanks
0 commit comments