For faster navigation, this Iframe is preloading the Wikiwand page for Zig (プログラミング言語).

Zig (プログラミング言語)

この項目「Zig (プログラミング言語)」は翻訳されたばかりのものです。不自然あるいは曖昧な表現などが含まれる可能性があり、このままでは読みづらいかもしれません。(原文:英語版 "Zig (programming language)" 2020年12月27日 (日) 23:57 (UTC)) 修正、加筆に協力し、現在の表現をより自然な表現にして下さる方を求めています。ノートページ履歴も参照してください。(2021年1月)
Zig
Zig
Zigのロゴ
パラダイム
登場時期
  • 2015年 ウィキデータを編集
開発者 アンドリュー・ケリー ウィキデータを編集
最新リリース 0.13.0 / 2024年6月6日[1]
型付け
影響を受けた言語 C言語C++GoRustJavaScript ウィキデータを編集
プラットフォーム クロスプラットフォーム
ライセンス MIT License ウィキデータを編集
ウェブサイト
拡張子 zig ウィキデータを編集
テンプレートを表示

Zigは、アンドリュー・ケリーによって設計された命令型汎用静的型付けコンパイル型システムプログラミング言語である[2][3]。 この言語は「堅牢性、最適性及び保守性」向けに設計されており[4][5]コンパイル時ジェネリクスリフレクションクロスコンパイル及び手動メモリ管理英語版をサポートしている[6]。 この言語の主な目標は、C言語に依存せずにこれを改善し[7][8]Rustなどから着想を得ることである[9]

Zigにはパックされた構造体[注釈 1]、多倍長整数[10]、複数のポインタ型などの低レベルプログラミングのための多くの機能がある[11]

リファレンス実装コンパイラはZig及びC++で記述されており、LLVM[12]をバックエンドとして使用し[13][14]、LLVMがサポートするターゲットの多くをサポートしている[15]。 コンパイラはフリーかつオープンソースで、MITライセンスの条件に基づいて配布されている[14]。 Zigのコンパイラはzig cc及びzig c++をそれぞれ使用することによって、Clangと同様にC言語及びC++をコンパイルすることができる[16]Nimプログラミング言語はC言語のコンパイラとしてzig ccを使用することをサポートしている[17]

コード例

[編集]

Hello world

[編集]
// zig version 0.9.1
const std = @import("std");

pub fn main() !void {
    const stdout = std.io.getStdOut().writer();
    try stdout.print("Hello, {s}!\n", .{"world"});
}

ジェネリック連結リスト

[編集]
// ジェネリックなLinkedList型

const std = @import("std");
const stdout = std.io.getStdOut().writer();

fn LinkedList(comptime T: type) type {
    return struct {
        const Self = @This();
        pub const Node = struct {
            next: ?*Node = null,
            data: T,
        };

        first: ?*Node = null,

        pub fn prepend(list: *Self, new_node: *Node) void {
            new_node.next = list.first;
            list.first = new_node;
        }
        pub fn format(
            list: Self,
            comptime fmt: []const u8,
            options: std.fmt.FormatOptions,
            out_stream: anytype,
        ) !void {
            try out_stream.writeAll("( ");
            var it = list.first;
            while (it) |node| : (it = node.next) {
                try std.fmt.formatType(node.data, fmt, options, out_stream, 1);
                try out_stream.writeAll(" ");
            }
            try out_stream.writeAll(" )");
        }
    };
}

pub fn main() !void {
    const ListU32 = LinkedList(u32);
    var list = ListU32{};
    var node1 = ListU32.Node{ .data = 1 };
    var node2 = ListU32.Node{ .data = 2 };
    var node3 = ListU32.Node{ .data = 3 };
    list.prepend(&node1);
    list.prepend(&node2);
    list.prepend(&node3);
    try stdout.print("{}\n", .{list});
    try stdout.print("{b}\n", .{list});
}
実行結果
( 3 2 1 ) 
( 11 10 1 )

このコードは、Zig言語を使用して単方向連結リスト(LinkedList)を定義し、それを使用して整数の単方向連結リストを作成し、標準出力に出力するプログラムである。

最初の2行では、stdパッケージからioモジュールをインポートし、標準出力ストリームを取得する。

次に、LinkedList関数が定義されている。この関数は、ジェネリックなLinkedList型を作成する。型Tを取り、LinkedList型を返す。このLinkedList型は、Nodeという構造体を含み、それぞれがデータを保持する。また、LinkedList型自体もprependとformatというメソッドを持つ。prependメソッドは、リストの先頭にノードを追加する。formatメソッドは、リストの内容を指定された書式でフォーマットして出力する。

main関数では、LinkedList関数を使用してListU32という型を作成し、整数のLinkedListを作成する。その後、3つのノードを作成し、prependメソッドを使用してリストに追加する。最後に、標準出力にリストを出力する。

脚注

[編集]

注釈

[編集]
  1. ^ フィールド間のパディングがゼロの構造体のこと。

出典

[編集]
  1. ^ 出典URL: https://ziglang.org/download/#release-0.13.0, 題名: Release 0.13.0
  2. ^ Motroc, Gabriela (2017年10月31日). ““Zig has all the elegant simplicity of C, minus all the ways to shoot yourself in the foot””. JAXenter. 2021年1月1日閲覧。
  3. ^ Elizabeth, Jane (2017年10月19日). “Tired of C? New programming language Zig aims to be more pragmatic and readable”. JAXenter. 2021年1月1日閲覧。
  4. ^ Yegulalp, Serdar (2016年8月29日). “New challenger joins Rust to topple C language”. InfoWorld. 2021年1月1日閲覧。
  5. ^ IT之家 (2020年7月12日). “想替代 C 的 Zig 语言成立了基金会” (中国語). 新浪数码. 2021年1月1日閲覧。
  6. ^ The Zig Programming Language”. ziglang.org. 2021年1月1日閲覧。
  7. ^ Mozilla’s Observatory, the Zig programming language, and uSens’ VR/AR SDK—SD Times news digest: Aug. 29, 2016”. SD Times (2016年8月29日). 2021年1月1日閲覧。
  8. ^ Zig competes with C instead of depending on it”. ziglang.org. 2021年1月1日閲覧。
  9. ^ Kelley, Andrew (2018年1月24日). “Unsafe Zig is Safer than Unsafe Rust”. andrewkelley.me. 2021年1月1日閲覧。
  10. ^ Anderson, Tim (2020年4月24日). “Keen to go _ExtInt? LLVM Clang compiler adds support for custom width integers”. The Register. 2021年1月1日閲覧。
  11. ^ Documentation - The Zig Programming Language”. ziglang.org. 2021年1月1日閲覧。
  12. ^ Lewkowicz, Jakub (2020年4月14日). “SD Times news digest: C++20 concepts in Visual Studio 2010 version 16.3, Bootstrap to drop IE support, and Zig 0.60 released”. SD Times. 2021年1月1日閲覧。
  13. ^ Bill, Ginger (2019年5月13日). “A Reply to The Road to Zig 1.0”. gingerBill. 2021年1月1日閲覧。
  14. ^ a b ziglang/zig”. GitHub. 2021年1月1日閲覧。
  15. ^ Tier System”. ziglang.org. 2021年1月1日閲覧。
  16. ^ zig cc”. ziglang.org (2020年4月13日). 2021年1月1日閲覧。
  17. ^ Add support for `zig cc` as C compiler. #13757”. GitHub. 2021年1月1日閲覧。

関連項目

[編集]

外部リンク

[編集]
{{bottomLinkPreText}} {{bottomLinkText}}
Zig (プログラミング言語)
Listen to this article

This browser is not supported by Wikiwand :(
Wikiwand requires a browser with modern capabilities in order to provide you with the best reading experience.
Please download and use one of the following browsers:

This article was just edited, click to reload
This article has been deleted on Wikipedia (Why?)

Back to homepage

Please click Add in the dialog above
Please click Allow in the top-left corner,
then click Install Now in the dialog
Please click Open in the download dialog,
then click Install
Please click the "Downloads" icon in the Safari toolbar, open the first download in the list,
then click Install
{{::$root.activation.text}}

Install Wikiwand

Install on Chrome Install on Firefox
Don't forget to rate us

Tell your friends about Wikiwand!

Gmail Facebook Twitter Link

Enjoying Wikiwand?

Tell your friends and spread the love:
Share on Gmail Share on Facebook Share on Twitter Share on Buffer

Our magic isn't perfect

You can help our automatic cover photo selection by reporting an unsuitable photo.

This photo is visually disturbing This photo is not a good choice

Thank you for helping!


Your input will affect cover photo selection, along with input from other users.

X

Get ready for Wikiwand 2.0 🎉! the new version arrives on September 1st! Don't want to wait?