LoginSignup
0
0

More than 5 years have passed since last update.

Ada言語 14日目 ファイル分割

Last updated at Posted at 2018-12-31

はじめに

クラスをやろうと思ったのですが、その前にファイル分割をできるようにしておくと良いかもしれないと思ったので、今回はファイル分割をやりました。(パッケージ化というのかな?)
開発環境は、IDEから離れてUbuntuの方でやりましたので、その際に作成したMakefileも一緒に載せておきます。

ソースと結果

main.adb
with Ada.Integer_Text_IO;
use Ada.Integer_Text_IO;

with pakkeizi;
use pakkeizi;

procedure main is

    hennsuu1 : Integer := 0;
    hennsuu2 : Integer := 0;

begin

    hennsuu1 := pakkeizi.pakkeizi_kannsuu1(20);

    Ada.Integer_Text_IO.Put(hennsuu1, 1);

    hennsuu2 := pakkeizi.pakkeizi_kannsuu2(20);

    Ada.Integer_Text_IO.Put(hennsuu2, 1);

end main;
pakkeizi.ads
package pakkeizi is

    function pakkeizi_kannsuu1(hikisuu : Integer) return Integer;
    function pakkeizi_kannsuu2(hikisuu : Integer) return Integer;

end pakkeizi;
pakkeizi.adb
with Ada.Text_IO;
use Ada.Text_IO;

package body pakkeizi is

    function pakkeizi_kannsuu1(hikisuu : Integer) return Integer is

    begin

        Ada.Text_IO.Put_Line("package function 1");

        return (hikisuu + 20);

    end pakkeizi_kannsuu1;

    function pakkeizi_kannsuu2(hikisuu : Integer) return integer is

        hennsuu : Integer := 0;

    begin

        Ada.Text_IO.Put_Line("package function 2");

        return (hikisuu + 100);

    end pakkeizi_kannsuu2;

end pakkeizi;
build:
    gcc -c main.adb
    gcc -c pakkeizi.adb
    gnatbind main
    gnatlink main

run:
    ./main

実行結果 1行目: package function 1
実行結果 2行目: 40package function 2
実行結果 3行目: 120

さいごに

次回こそはクラスをやりたいと思います。
IDEの方でもファイル分割をできるようにしたいとも思います。

良いお年を。

日記一覧へ

Ada言語を習得する日記一覧

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0