Last active
October 14, 2018 07:58
-
-
Save jrfondren/705ea4119f44bc744c3abe353451709f to your computer and use it in GitHub Desktop.
Translating 'elegant' C to Zig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const c = @cImport({ | |
@cInclude("stdio.h"); | |
}); | |
pub fn main() void { | |
const str = c"\x00" ++ "*" ** 8; | |
var s = @ptrCast([*]const u8, &str[8]); | |
while (s[0] != 0) : (s -= 1) { | |
_ = c.puts(s); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main(void) { | |
const char* s = "\0********" + 9; | |
while (*--s) | |
puts(s); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const std = @import("std"); | |
pub fn main() !void { | |
const stdout = try std.io.getStdOut(); | |
comptime var width = 1; | |
inline while (width <= 8) : (width += 1) { | |
try stdout.write("*" ** width ++ "\n"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment