2014年4月5日土曜日

開発環境

C++実践プログラミング (スティーブ オウアルライン (著)、Steve Oualline (原著)、Steve Oualline(原著)、望月 康司(翻訳)、クイープ(翻訳) 、オライリー・ジャパン)のⅣ部(高度なプログラミング概念)の17章(デバッグと最適化)、17.8(最適化)、17.8.4(システムライブラリの使用)、設問 17-1.を解いてみる。

その他参考書籍

設問 17-1.

コード(BBEdit, Emacs)

sample341.cpp

#include <iostream>
#include <cstring>

const int X_SIZE = 20;
const int Y_SIZE = 10;

int matrix[X_SIZE][Y_SIZE];

inline void init_matrix() {
  // memsetは文字(8ビット、1バイト)を埋める関数
  // 整数(int)は4バイトで、-1は0xffffffff、よって0xffで埋められ、
  // matrixの各値は0xffffffff、すなわち-1になる
  // 1は0x00000001、よって0x01で埋められ、matrixの各値は0x01010101、
  // すなわち、16843009になる
  std::memset(matrix, 1, sizeof(matrix));
}

int main(int argc, char *argv[])
{
  int i;
  int j;

  init_matrix();
  for (i = 0; i < X_SIZE; ++i) {
    for (j = 0; j < Y_SIZE; ++j)
      std::cout << matrix[i][j] << ' ';
    std::cout << '\n';
  }

  return (0);
}

Makefile

#
# FSFのg++コンパイラ用のMakefile
#
CC=g++
CFLAGS=-g -Wall
all: sample341

sample341: sample341.cpp
 ${CC} ${CFLAGS} -o sample341 sample341.cpp

clean:
 rm sample341

入出力結果(Terminal)

$ make && ./sample341
g++ -g -Wall -o sample341 sample341.cpp
16843009 16843009 16843009 16843009 16843009 16843009 16843009 16843009 16843009 16843009 
16843009 16843009 16843009 16843009 16843009 16843009 16843009 16843009 16843009 16843009 
16843009 16843009 16843009 16843009 16843009 16843009 16843009 16843009 16843009 16843009 
16843009 16843009 16843009 16843009 16843009 16843009 16843009 16843009 16843009 16843009 
16843009 16843009 16843009 16843009 16843009 16843009 16843009 16843009 16843009 16843009 
16843009 16843009 16843009 16843009 16843009 16843009 16843009 16843009 16843009 16843009 
16843009 16843009 16843009 16843009 16843009 16843009 16843009 16843009 16843009 16843009 
16843009 16843009 16843009 16843009 16843009 16843009 16843009 16843009 16843009 16843009 
16843009 16843009 16843009 16843009 16843009 16843009 16843009 16843009 16843009 16843009 
16843009 16843009 16843009 16843009 16843009 16843009 16843009 16843009 16843009 16843009 
16843009 16843009 16843009 16843009 16843009 16843009 16843009 16843009 16843009 16843009 
16843009 16843009 16843009 16843009 16843009 16843009 16843009 16843009 16843009 16843009 
16843009 16843009 16843009 16843009 16843009 16843009 16843009 16843009 16843009 16843009 
16843009 16843009 16843009 16843009 16843009 16843009 16843009 16843009 16843009 16843009 
16843009 16843009 16843009 16843009 16843009 16843009 16843009 16843009 16843009 16843009 
16843009 16843009 16843009 16843009 16843009 16843009 16843009 16843009 16843009 16843009 
16843009 16843009 16843009 16843009 16843009 16843009 16843009 16843009 16843009 16843009 
16843009 16843009 16843009 16843009 16843009 16843009 16843009 16843009 16843009 16843009 
16843009 16843009 16843009 16843009 16843009 16843009 16843009 16843009 16843009 16843009 
16843009 16843009 16843009 16843009 16843009 16843009 16843009 16843009 16843009 16843009
$

0 コメント:

コメントを投稿