• 検索結果がありません。

プログラミング演習

N/A
N/A
Protected

Academic year: 2021

シェア "プログラミング演習"

Copied!
19
0
0

読み込み中.... (全文を見る)

全文

(1)

プログラミング演習 II

2003 年 1 1月 19 日(第 6 回)

木村巌

(2)

今日やること

複数のファイルから成るプログラム

乗算に備えて、データ型の実装の拡張

構造体、構造体のポインタ、 typedef

(3)

復習

前回は、正負の整数の加減算を実装し

(4)

プログラムの分割

実際に処理を行う main() 関数と、それ に密接に関連した関数群

Mpi の乗除算などを行う関数群 のように、分割した方が便利

変更していない部分をコンパイルし直さな いでよい

(5)

プログラムの分割

たとえば、 main() 関数を含む main.c

Mpi 関連の関数は、 mpilib.c などとする Mpi 関連の関数のプロトタイプ宣言、

定数の define などは、ヘッダーファイ

ルにする

(6)

コンパイルの仕方

二つのファイルを同時にコンパイル、

リンクして main を得る gcc –o main main.c mpilib.c

それぞれのファイルをコンパイル、そ の後手動でリンクして main を得る

gcc –c main.c gcc –c mpilib.c

gcc –o main main.o mpilib.o

(7)

コンパイルの仕方(続き)

main.c

のみ変更した場合は

gcc –c main.c

gcc –o main main.o mpilib.o

のように、

mpilib.c

のコンパイルを省い てよい

あるいは、

gcc –o main main.c mpilib.o

でもよい(

main.c

のコンパイルとリン

クを同時に)

(8)

Main.c

#include <stdio.h>

#include <stdlib.h>

#include “mpilib.h”

/* ダブルクォーテーションはコンパイラのデフォ ルト以外のヘッダファイルを読み込ませる  */

Int

main (int ac, char *av[]) {

}

(9)

mpilib.h

#define DIM 4

#define BASE 10 /* prototypes */

Long *mpi_add (long *a, long *b);

などなど

(10)

mpilib.c

プログラム本体

#include <stdio.h>

#include <stdlib.h>

#include “mpilib.h”

...

(11)

なぜヘッダファイルが必要か

変数には、「スコープ」(可視範囲)があっ た

関数についても同様だが、関数名は自動的に 外部へ輸出される

しかし関数のプロトタイプは明示的に宣言しなけ れば行けない

前期( 611 日の回)の、「変数のスコー プ」を参照

一つのファイル内で宣言された変数名は、そ のファイル内で可視

(12)

構造体( structure )

教科書 11 章

異なる型を一つに集約する

配列は、同じ型の値のみ保持できた

(13)

構造体の宣言

struct tag 名 {

型名 メンバ 1;

型名 メンバ 2;

…….

};

(14)

構造体の例

struct mpi {

int dim;

long *digits;

};

struct mpi a;

(15)

構造体のメンバへのアクセス

struct mpi a; /*  の時は */

a.dim;

a.digits;

によって、構造体 a の各メンバーにアク

セスできる

(16)

型宣言、構造体へのポインタ

教科書 11.2, 11.3

プログラム例 mpistruct.c

(17)

レポート課題

Web

に掲示した

mpi3.c

を、

main.c main() 関数のみを含む)

mpilib.h (プロトタイプ宣言や define を含 む)

mpilib.c (実際の関数定義などを含む)

に分割せよ.ただし、従来の

long *

によ る

mpi

ではなく、今日説明した

mpi_t

に 変更すること

コンパイルして、実行した様子も示せ

(18)

レポート課題提出要領

2003

11

25

日(火)一杯に、木村 までメールで送ること.

アドレスはiwao@sci.toyama-u.ac.jp

添付ファイルではなく、できるだけメー ル本文にレポート本文を記載してくださ い.

文献や友人のレポートを参考にした場合

は、それを明記のこと.

(19)

レポートについての注意

資料や他の人のレポートを参考にした 場合は、それを理解すること

間違ったレポートを引き写したとしか いえないものが散見されます

自分で考えてもわからず、人のレポー トも十分に理解できないのでは、全く 意味がない

十分理解できないなら、授業に出席し

て質問してください.

参照

関連したドキュメント

H ernández , Positive and free boundary solutions to singular nonlinear elliptic problems with absorption; An overview and open problems, in: Proceedings of the Variational

Keywords: Convex order ; Fréchet distribution ; Median ; Mittag-Leffler distribution ; Mittag- Leffler function ; Stable distribution ; Stochastic order.. AMS MSC 2010: Primary 60E05

For example, a maximal embedded collection of tori in an irreducible manifold is complete as each of the component manifolds is indecomposable (any additional surface would have to

Its Tamari polynomial B T (x) counts the trees smaller than or equal to T in the Tamari order according to the number of nodes on their

Key words: determinantal point processes; Sturm–Liouville operators; scaling limits; strong operator convergence; classical random matrix ensembles; GUE; LUE; JUE; MANOVA

Condition (1.2) and especially the monotonicity property of K suggest that both the above steady-state problems are equivalent with respect to the existence and to the multiplicity

In this article we prove a classification theorem (Main theorem) of real planar cubic vector fields which possess two distinct infinite singularities (real or complex) and

Since the Shimura series has an integral presentation as a Rankin-Selberg con- volution of Siegel’s theta series and a Hilbert modular form, we recall here the definition and