開発環境
- OS X Mavericks - Apple(OS)
- Emacs (CUI)、BBEdit - Bare Bones Software, Inc. (GUI) (Text Editor)
- C++ (プログラミング言語)
- g++(コンパイラ)
C++実践プログラミング (スティーブ オウアルライン (著)、Steve Oualline (原著)、Steve Oualline(原著)、望月 康司(翻訳)、クイープ(翻訳) 、オライリー・ジャパン)のⅡ部(シンプルなプログラミング)の10章(C++ プリプロセッサ)、10.1(#define文)、設問 10-2を解いてみる。
その他参考書籍
- C++プログラミング入門 (グレゴリー サティア (著)、ダウグ ブラウン (著)、Gregory Satir (原著)、Doug Brown (原著)、望月 康司 (翻訳)、谷口 功 (翻訳)、オライリージャパン)
設問 10-2
コード(BBEdit, Emacs)
sample.cpp
#include <iostream> /* =を無くす */ #define MAX 10 int main() { int counter; /* 問題のコードの=があるままだと、初期化がcounter==10となってしまう */ for (counter=MAX; counter > 0; --counter) { std::cout << "Hi there\n"; } return (0); }
Makefile
# # FSFのg++コンパイラ用のMakefile # CC=g++ CFLAGS=-g -Wall all: sample sample: sample.cpp $(CC) $(CFLAGS) -o sample sample.cpp clean: rm sample
入出力結果(Terminal)
$ make && ./sample g++ -g -Wall -o sample sample.cpp Hi there Hi there Hi there Hi there Hi there Hi there Hi there Hi there Hi there Hi there $
0 コメント:
コメントを投稿