mirror of
https://codeberg.org/andyscott/ziglings.git
synced 2024-12-22 14:03:10 -05:00
inserted a workaround for mac-os, see https://github.com/ziglang/zig/issues/14657#issuecomment-1432180967
This commit is contained in:
parent
4cf3bd63a2
commit
9693860bc0
2 changed files with 13 additions and 4 deletions
|
@ -49,13 +49,22 @@ const c = @cImport({
|
||||||
|
|
||||||
pub fn main() void {
|
pub fn main() void {
|
||||||
|
|
||||||
|
// Due to a current limitation in the Zig compiler,
|
||||||
|
// we need a small workaround to make this exercise
|
||||||
|
// work on mac-os.
|
||||||
|
const builtin = @import("builtin");
|
||||||
|
const stderr = switch (builtin.target.os.tag) {
|
||||||
|
.macos => 1,
|
||||||
|
else => c.stderr,
|
||||||
|
};
|
||||||
|
|
||||||
// In order to output a text that can be evaluated by the
|
// In order to output a text that can be evaluated by the
|
||||||
// Zig Builder, we need to write it to the Error output.
|
// Zig Builder, we need to write it to the Error output.
|
||||||
// In Zig we do this with "std.debug.print" and in C we can
|
// In Zig we do this with "std.debug.print" and in C we can
|
||||||
// specify the file to write to, i.e. "standard error (stderr)".
|
// specify the file to write to, i.e. "standard error (stderr)".
|
||||||
//
|
//
|
||||||
// Ups, something is wrong...
|
// Ups, something is wrong...
|
||||||
const c_res = fprintf(c.stderr, "Hello C from Zig!");
|
const c_res = fprintf(stderr, "Hello C from Zig!");
|
||||||
|
|
||||||
// let's see what the result from C is:
|
// let's see what the result from C is:
|
||||||
std.debug.print(" - C result ist {d} chars\n", .{c_res});
|
std.debug.print(" - C result ist {d} chars\n", .{c_res});
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
58c58
|
63c63
|
||||||
< const c_res = fprintf(c.stderr, "Hello C from Zig!");
|
< const c_res = fprintf(stderr, "Hello C from Zig!");
|
||||||
---
|
---
|
||||||
> const c_res = c.fprintf(c.stderr, "Hello C from Zig!");
|
> const c_res = c.fprintf(stderr, "Hello C from Zig!");
|
||||||
|
|
Loading…
Reference in a new issue