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

第2章. デバッグ、テスト、文書化

この作品はAIを使って翻訳されている。ご意見、ご感想をお待ちしている:translation-feedback@oreilly.com

ハイハイ

Windowsの上

私が混乱していると思っているのだろう、

私は待っている.

私の今の策略を完成させる。

ワイヤー『アイ・アム・ザ・フライ

この章では、デバッグ、テスト、文書化のためのツールについて説明する。

C言語ではメモリを使ってバカなことをする自由があるので、デバッグとは、(GDBを使った)ロジックのチェックという日常的な問題と、(Valgrindを使った)メモリの割り当てミスやリークのチェックという、より技術的な問題の両方を意味する。ドキュメンテーションの面では、この章ではインタフェース・レベルのツール(Doxygen)と、プログラムの各ステップのドキュメンテーションと開発を支援するツール(CWEB)を取り上げる。

この章では、テストハーネスについても簡単に紹介する。テストハーネスを使えば、コードに対してたくさんのテストを素早く書くことができるし、エラー報告や入力エラーやユーザエラーの処理についても、いくつか考慮すべき点がある。

デバッガを使う

デバッガーに関する最初のヒントは、シンプルで簡潔なものだ:

常にデバッガーを使うこと。

というのも、デバッガーを使わない人などいないだろうからだ。なぜなら、デバッガーを使わない人などいないからだ。この本の第2版では、第1版に関して最も多かった要望のひとつが、多くの読者にとってまったく新しいものであったデバッガーについて、より広範に紹介することであったと言える。

ッガーは変数の状態� �バックトレースとい� ��た低いレベルの情しか提供しないのに� �バグは一般的に広い� ��味での理解のエラから発生すると心配� �る人もいる。実際、� ��バッガーを使ってグを突き止めた後、� �なたが発見した根本� ��な問題や理解の誤が何なのか、そして� �れがあなたのコード� ��の他の場所でも同ように起こるのかど� �かを時間をかけて検� ��する価値はある。亡診断書の中には、� �因を積極的に尋ねる� ��のがある:__________________、 、 、 、 、 、 、 、 、 、 、 、 、 、、 、 、 、 、 、、 、 、 、 、 、 、______ 、 、______。 デバッガーがこのような調査を助け、コードの理解を深めた後、その理解をより多くの単体テストにカプセル化することができる。

デバッガの下でプログラミングを実行することに、実質的なコストはかからない。デバッガーは、何かが壊れたときに引っ張り出すだけのものでもない。リーナス・トーバルズはこう説明する:「私はいつもgdbを使っている......プログラミングができるステロイド上の逆アセンブラとしてね」。 print verbose++print i=100continuefor (int i=0; i<10; i++) のループから強制的に抜け出したり、一連のテスト入力を投げかけて関数をテストしたりできる。対話型言語のファンたちは、コードと対話することで開発プロセスが改善されるというのは正しいことだ。

どのような意図であれ、デバッガを使いこなすためには、人間が読めるデバッグ情報(変数や関数の名前付けなど)をプログラムにコンパイルしておく必要がある。デバッグ・シンボルを含めるには、コンパイラ・スイッチ(つまり、 ...

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