Skip to content

Instantly share code, notes, and snippets.

@jrfondren
Last active October 14, 2018 07:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrfondren/705ea4119f44bc744c3abe353451709f to your computer and use it in GitHub Desktop.
Save jrfondren/705ea4119f44bc744c3abe353451709f to your computer and use it in GitHub Desktop.
Translating 'elegant' C to Zig
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);
}
}
#include <stdio.h>
int main(void) {
const char* s = "\0********" + 9;
while (*--s)
puts(s);
}
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