Head First C ―頭とからだで覚えるCの基本
(オライリージャパン)
David Griffiths (著) Dawn Griffiths (著)
中田 秀基(監訳)(翻訳) 木下 哲也 (翻訳)
開発環境
- OS X Yosemite - Apple, Ubuntu (OS)
- Emacs (CUI)、BBEdit - Bare Bones Software, Inc. (GUI) (Text Editor)
- C (プログラミング言語)
- Clang/LLVM (コンパイラ, Xcode - Apple)
Head First C ―頭とからだで覚えるCの基本(David Griffiths (著)、Dawn Griffiths (著) 中田 秀基(監訳)(翻訳)、木下 哲也 (翻訳)、オライリージャパン)の6章(データ構造と動的メモリ: 架け橋を築く)、大きな疑問(p.305)を解いてみる。
その他参考書籍
- プログラミング言語C 第2版 ANSI規格準拠 (B.W. カーニハン D.M. リッチー (著)、 石田 晴久 (翻訳)、共立出版)
- プログラミング言語Cアンサー・ブック 第2版 (クロビス・L.トンド、スコット・E.ギンペル(著)、矢吹 道郎(翻訳))
- C実践プログラミング 第3版 (Steve Oualline (著)、 望月 康司 (監訳) (翻訳)、 谷口 功 (翻訳)、 オライリージャパン)
大きな疑問(p.305)
- 19bytes
- ロレッタ・バーンスワース
-
current->question = strdup(question);
-
free(current->question); current->question = strdup(question);
確認。(ValgrindがYosemiteにまだ対応してないみたいだから、VMware fusion上のUbuntuで確認。)
Makefile
P= CC=cc CFLAGS=-g -Wall # -O3 SRC= OBJ= LDLIBS= $(P): $(OBJ) $(CC) $(CFLAGS) $(LDLIBS) $(OBJ) -o $@
入出力結果(Terminal)
$ make spies cc -g -Wall spies.c -o spies $ valgrind --leak-check=full ./spies ==5285== Memcheck, a memory error detector ==5285== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al. ==5285== Using Valgrind-3.10.0.SVN and LibVEX; rerun with -h for copyright info ==5285== Command: ./spies ==5285== 容疑者はひげを生やしているか? (y/n): n 123456789012345678? (y/n): n 容疑者は誰? 12 12には当てはまり、123456789012345678には当てはまらない質問は? 1234567890 再実行しますか ? (y/n): n ==5285== ==5285== HEAP SUMMARY: ==5285== in use at exit: 0 bytes in 0 blocks ==5285== total heap usage: 11 allocs, 11 frees, 222 bytes allocated ==5285== ==5285== All heap blocks were freed -- no leaks are possible ==5285== ==5285== For counts of detected and suppressed errors, rerun with: -v ==5285== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) $
0 コメント:
コメントを投稿