Skip to Content
21st Century C, 2nd Edition
book

21st Century C, 2nd Edition

by Ben Klemens
May 2025
Intermediate to advanced
408 pages
5h 55m
Japanese
O'Reilly Media, Inc.
Content preview from 21st Century C, 2nd Edition

付録A C 101

この付録は言語の基本をカバーしている。万人向けではない。

  • すでにPython、Ruby、Visual Basicのような一般的なスクリプト言語でコードを書いた経験があれば、この付録はあなたのレベルに合うだろう。変数、関数、ループ、その他の基本的な構成要素について説明する必要はないので、この付録のメイン見出しは、C言語と一般的なスクリプト言語との大きな違いについてである。

  • 昔C言語を学んで錆びついたと感じている人は、このチュートリアルをざっと読めば、C言語を他とは違うユニークなものにしている癖を思い出すはずだ。

  • すでにC言語を日常的に使用しているのであれば、この付録をわざわざ読む必要はない。また、第II部の序盤も読み飛ばすか、ざっと目を通した方がよいだろう。これらは、C言語の核心に関するよくあるエラーや誤解を対象としている。

このチュートリアルが終わるまでにC言語のエキスパートになれるとは思わないでほしい。しかし、本書のパートIIを読めば、C言語のニュアンスや便利な習慣を発見することができるだろう。

構造

カーニガン&リッチー夫妻が1978年に出版した大ヒット本でやったように、チュートリアルを始めよう。

//tutorial/hello.c
#include <stdio.h>

int main(){
    printf("Hello, world.\n");
}

最初の行の二重スラッシュは、コンパイラが無視するコメントを示す。この付録の中で、このようなファイル名がついているコード・サンプルはすべて、https://github.com/b-k/21st-Century-Examples

これだけでも、C言語に関するいくつかの重要な点が明らかになる。構造的には、C言語プログラムのほとんどすべてがそうである:

  • のようなプリプロセッサ・ディレクティブである。#include <stdio.h>

  • 変数または型の宣言(ただし、このプログラミングには何もない)

  • main のようなファンクションブロックで、評価する式を含む(printf のような)。

しかし、プリプロセッサ指示文、宣言、ブロック、式の定義や使い方について詳しく説明する前に、このプログラムをどのように実行すればコンピューターが挨拶してくれるかを考えなければならない。

C言語ではコンパイル・ステップが必要で、これは1つのコマンドを実行するだけである。

スクリプト言語には、スクリプトのテキストを解析するプログラムが付属している。C言語には、プログラムのテキストを取り込み、オペレーティング・システムで実行されるプログラムを直接生成するコンパイラがある。コンパイラを使うのは面倒なので、コンパイラを実行するためのプログラミングがある。統合開発環境(IDE)には通常、コンパイル・アンド・ラン・ボタンがあり、コマンドラインでは、make というPOSIX標準プログラムがコンパイラを実行してくれる。

もしコンパイラとmake を持っていないなら、「パッケージマネージャを使う」で入手方法を読み取ってほしい。簡単に説明すると、gcc またはclang 、そしてmake をインストールするよう、パッケージマネージャに依頼する。

コンパイラーとmake がインストールされている状態で、上記のプログラミングをhello.cとして 保存した場合、make を使ってこのコマンドでコンパイラーを実行できる:

make hello

これはhello プログラムを出力するもので、コマンドラインから実行するか、ファイルブラウザでクリックして、期待通りのファイルが出力されるかを確認することができる。 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Learn C Programming - Second Edition

Learn C Programming - Second Edition

Jeff Szuhay
Tiny C Projects

Tiny C Projects

Daniel Gookin

Publisher Resources

ISBN: 9798341650848