당신은 Zigged(시리즈): 소개와 Hello World

발행: (2026년 6월 9일 AM 02:25 GMT+9)
4 분 소요
원문: Dev.to

Source: Dev.to

Blog no. 01

최근에 Andrew Kelly의 YouTube 영상(link-1, link-2)을 보고 zig의 팬이 되었습니다. ziglings 연습문제를 풀어보면서 언어에 매료됐고, 이제 zig로 직접 코딩해 보고 싶습니다. 친구이자 멘토인 Praseed Pai 덕분에 여기서 (GNULinux.pdf) 간단한 C/C++ 프로그램들을 zig로 다시 작성해 보면서 배우기로 했습니다. 이 프로그램들은 환경 변수, 명령줄 인자, 파이프, IPC 등 중요한 주제를 우아하게 다루고 있어 재미있을 것이라 생각합니다. 진행하면서 제 여정을 여러분과 공유하고 싶습니다. 저와 같이 즐겨 주시길 바랍니다.

이 블로그를 읽기 전에 필요한 사전 지식

  • 제 목표는 여러분에게 몇 가지 zig 프로그램을 보여 줘서 직접 손에 익히게 하는 것입니다. zig가 무엇인지, 어떤 목표를 가지고 있는지, 혹은 C/Rust/Go와 어떻게 다른지에 대해서는 다루지 않을 것입니다. 이를 이해하려면 Mr. Kelly의 강연과 인터뷰를 반드시 시청하세요. 원천에서 직접 정보를 얻는 것이 입소문을 타고 얻는 것보다 낫다고 믿습니다.
  • Ziglings
  • 네이티브 프로그래밍이 C#/Java/Python 같은 크로스‑플랫폼 프로그래밍과 어떻게 다른지에 대한 기본 지식.
  • C에 대한 약간의 경험(곧 등장할 인터옵 프로그램을 이해할 정도).
  • C ABI가 무엇인지 모른다면 찾아보세요. (제가 철자를 정확히 썼습니다)
  • zig 컴파일러가 설치되어 있고 PATH에 등록되어 있어야 합니다.

zig에서 Hello World를 구현하는 세 가지 방법을 소개합니다.

먼저, 가장 기본적인 프로그램입니다.

// helloworld.zig
const std = @import("std");

pub fn main(init: std.process.Init) !void {
    // debug print. this writes to standard error, not standard out
    std.debug.print("Hello, World! This is written using debug.print.\n", .{});

    // writing to standard out without buffer
    try std.Io.File.writeStreamingAll(.stdout(), init.io, "Hello, World! This is written using writeStreamingAll\n");

    // writing to standard out with buffer (recommended approach)
    // step 1: create a buffer array to hold string data.
    var buffer: [1024]u8 = undefined;
    // step 2: call the Writer.init method and pass in init.io.
    var file_writer = std.Io.File.Writer.init(.stdout(), init.io, &buffer);
    // step 3: strip type and take the interface so we have the option to
    // write to anything including sockets or files and not just stdout.
    var stdout_writer = &file_writer.interface;
    // step 4: use the print method to print
    try stdout_writer.print("Hello, World! This is written using Writer.print\n", .{});
    // step 5: finally, before exiting, make sure you flush the buffer to screen
    try stdout_writer.flush();
}

이제 프로그램을 실행해 보겠습니다. 저는 Windows 환경에서 작업하고 있지만, 명령어는 모든 플랫폼에서 동일합니다.

C:/learn_zig>zig run helloworld.zig

위 명령은 디버그 모드로 프로그램을 실행합니다. 이제 실행 파일을 빌드하는 방법을 살펴보겠습니다.

C:/learn_zig>zig build-exe -O ReleaseSafe helloworld.zig
0 조회
Back to Blog

관련 글

더 보기 »