2014年2月19日水曜日

開発環境

C++実践プログラミング (スティーブ オウアルライン (著)、Steve Oualline (原著)、Steve Oualline(原著)、望月 康司(翻訳)、クイープ(翻訳) 、オライリー・ジャパン)のⅡ部(シンプルなプログラミング)の10章(C++ プリプロセッサ)、10.1(#define文)、設問 10-2を解いてみる。

その他参考書籍

設問 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 コメント:

コメントを投稿