$B7W;;5!=xO@#2!J#2#0#1#1G/EY!K

$B7W;;5!=xO@#2(B, $B, www.kameda-lab.org 2011/10/24b

1. Hello World $B$J$i$L(B Hello ESYS

$B$^$:$O%W%m%0%i%_%s%0$NI|=,$+$i;O$a$^$7$g$&!#(B

1.1 Hello ESYS ($B$R$I$$Nc(B)

$B$^$:$O7W;;5!=xO@#1$^$G$NI|=,$,$F$i!"%&%)!<%_%s%0%"%C%W$G$9!#(B
$B0J2<$N%5%s%W%k$O!V0-$$Nc!W$G$9!#$3$s$J=q$-J}$7$F$-$??M$OH?>J!#(B

ic2-week1-HelloESYS-Simple.c

$B2?$,0-$$$N$G$7$g$&$+!)(B
$B/$J$/$H$b#4$D$O;XE&$G$-$k$Y$-$G$9$M!#(B


1.2 Hello ESYS $B$r$^$H$b$J7A$K$7$F$_$h$&(B

ic2-week1-HelloESYS-Simple.c

$B2?$,0-$+$C$?$N$G$7$g$&$+!)(B
$B ic2-week1-HelloESYS-Better.c

$B0c$$$,$o$+$j$^$9$+!)(B

$B%3%^%s%I%i%$%s$G$N%3%s%Q%$%kJ}K!$b!":#8e$O(B
$ gcc -Wall -o $B%?!<%2%C%HL>(B $B%=!<%9(BC$B%U%!%$%k(B
$ gcc -Wall -o ic2-week1-HelloESYS-Better ic2-week1-HelloESYS-Better.c

$B$G

1.3 Hello ESYS $B$r$5$i$KCzG+$K=q$$$F$_$?$i!)(B

$B>/$7H/E8%l%Y%k$K$J$j$^$9$,!"$h$jCzG+$K5-=R$9$k$J$i!"2<5-$N$h$&$K=q$$$F$*$/$N$b$h$$$G$7$g$&!#(B

ic2-week1-HelloESYS-Full.c


1.4 $BH/E8!';H$&$HJXMx$J%^%/%m(B

C$B8@8l%W%j%W%m%;%C%5$K$h$k%^%/%m$K$D$$$F$O$9$G$K=,$C$F$$$k$HJ9$$$F$^$9!#(B
$B<+J,$GDj5A$7$F;H$&$N$O$b$A$m$s(BOK$B$G$9$,!"(BC$B%3%s%Q%$%i$N;EMM$G$b$H$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-o ic2-week1-ReadFile-NotSoGood ic2-week1-ReadFile-NotSoGood.c
$ emacs abc.txt ($B$J$K$+:n@.$7$F$_$^$7$g$&!#:#2s$OCf?H$O6u$G$b9=$$$^$;$s!#(B)
$ ls ($B>/$J$/$H$b(B ic2-week1-ReadFile-NotSoGood, ic2-week1-ReadFile-NotSoGood.c, abc.txt$B$O$"$k$O$:(B)
$ ./ic2-week1-ReadFile-NotSoGood abc.txt ($B$^$H$b$KF0$/Nc(B)
$ ./ic2-week1-ReadFile-NotSoGood
$ ./ic2-week1-ReadFile-NotSoGood def.txt
$ chmod u-r abc.txt
$ ./ic2-week1-ReadFile-NotSoGood abc.txt
$ chmod u+r abc.txt
$ ./ic2-week1-ReadFile-NotSoGood abc.txt

$B2?2s%;%0%a%s%F!<%7%g%s%U%)!<%k%H$r8+$^$7$?$+!)$=$NM}M3$,J,$+$j$^$9$+!)(B
$B$3$l$i$N%;%0%a%s%F!<%7%g%s%U%)!<%k%H$O9T57$N$h$$%W%m%0%i%`$r=q$1$P!J@5$7$/H~$7$$(BC$B8@8l$rOC$;$P!K$9$Y$F2sHr$G$-$^$9!#(B


2.2 $B%U%!%$%k$r3+$$$F!J>-Mh!"%G!<%?$rFI$`=`Hw!K$^$C$H$&$J=q$-J}(B

$B2<$N%W%m%0%i%`$O!"MM!9$J>u67$,Mh$F$bBP1~$G$-$k$h$&$K$J$C$F$$$k%W%m%0%i%`$G$9!#(B
$B%f!<%6$,$^$H$b$K%U%!%$%k$r;XDj$7$F$/$l$k(B($B>e5-$N!V$^$H$b$KF0$/Nc!W!K$H$O8B$j$^$;$s!#(B
$B3'$5$s$,;H$&%7%9%F%`4X?t$O!"l9g!"JVCM$G65$($F$/$l$^$9!#(B
$B$=$NCM$r>e$B$=$l$>$l$N%7%9%F%`4X?t$NJVCM$N0UL#$O!"(Bman$B%Z!<%8$r;2>H$7$F$/$@$5$$(B($B$J$$$7$O%0%0$C$F$b$h$7!#$?$@$7(BWindows$BMQ$H$+$G$J$/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B$=$&$9$k$H!"$=$N$&$A!"4v$D$+$N4X?t$O@N$K=q$$$?$-$j!";H$&$@$1$GJQ99$H$+0l@Z$7$J$/$J$C$?$j$7$^$9!#(B
$B$3$&$$$&@N=q$$$F!"$b$&JQ99$7$J$$4X?t$O!"JL%U%!%$%k$KJ,$1$F$*$/$H!";v8N!J8m$C$F=q$-49$($F$7$^$&!K$rKI$0$3$H$,$G$-$^$9!#(B

3.3$B$N(B ic2-week1-Calculations-Functions.c $B$K=P$F$-$F$$$?4X?t72$r!"(Bmain$B4X?t$NF~$C$F$$$k%U%!%$%k$HJL$N%U%!%$%k$NJ,$1$F=q$/$h$&$K$7$F$_$^$7$g$&!#(B
$B:#2s$O!"!V<+>h!W$H!V#2G\!W$9$k4X?t$@$1$O#1$D$N%U%!%$%k$K$^$H$a$F$_$?$N$G!"(Bmain$B4X?t$N%U%!%$%k$HJ;$;$F9g7W#5$D$N%U%!%$%k$KJ,$1$^$9!#(B

ic2-week1-Calculations-Main.c (main$B4X?tB&(B)

$B0J2<$OJ,3d$5$l$?B&(B
ic2-week1-Calculations-Sub-Input.c $B!V?tCMF~NO!W(B
ic2-week1-Calculations-Sub-Square-And-Double.c $B!V<+>h!W!V#2G\!W(B
ic2-week1-Calculations-Sub-Divide3.c $B!V#3$G3d$j$-$l$k$+!)!W(B
ic2-week1-Calculations-Sub-RepeatTwice.c $B!V7e$rG\$K$7$FI=<(!W(B

main$B4X?tB&$N!"(Bmain()$B$ND>A0$K;D$5$l$?#59T$KCmL\$7$F$/$@$5$$!#(B
$BB>$N%=!<%9$OA4$FJ,3d$5$l$?B&$KAw$j=P$5$l$^$7$?$,!"$=$l$>$l$N4X?t$N7?$@$1$O!"(Bmain$B4X?t$N%U%!%$%k$K;D$7$F$"$j$^$9!#(B
$B%3%s%Q%$%i$,(Bmain()$BFbIt$NJ8K!$G@09g$,$B%3%s%Q%$%k$O!"#2CJ3,$KJ,$+$l$^$9!#(B
$B#1CJL\$O!"3F%=!<%9$r%*%V%8%'%/%H%U%!%$%k$KJQ49$9$k695A$N!V%3%s%Q%$%k!W$G$9!#(B
$B>e5-#5%U%!%$%k$H$b!"2<5-$HF1$8MWNN$G(B($B695A$N(B)$B%3%s%Q%$%k$7$^$9!#(B

$ gcc -Wall -c ic2-week1-Calculations-Main.c

$B#2CJL\$O!"%*%V%8%'%/%H%U%!%$%k$rA4$F7k9g$7$F$B$3$l$O7k9gM=Dj$N%*%V%8%'%/%H%U%!%$%k$rA4$F=`Hw$7$F$+$i9T$$$^$9!#(B
gcc$B$N(B-o$B%*%W%7%g%s$G4uK>$9$k$r;XDj$7$?$"$H!"%j%s%/M=Dj$N%*%V%8%'%/%H%U%!%$%k$rA4$FJB$Y$^$9!#(B
($B2~9T$;$:$KA4It#19T$GF~NO$9$k$3$H(B)

$ gcc -o ic2-week1-Calculations-A ic2-week1-Calculations-Sub-Input.o ic2-week1-Calculations-Sub-Square-And-Double.o ic2-week1-Calculations-Sub-Divide3.o ic2-week1-Calculations-Sub-RepeatTwice.o ic2-week1-Calculations-Main.o

$B%3%s%Q%$%k$,$@$s$@$sLLE]$K$J$C$F$-$?$N$G!"(Bbash$B$N%9%/%j%W%H$rMQ0U$7$F$_$^$7$?!#(B
$B%3%^%s%I%i%$%s$GBG$DFbMF$O!"$3$NMM$K%F%-%9%H%U%!%$%k$K$7$F$*$/$3$H$G!"A4$F0l5$$K(Bbash$B$K$B$?$@$7!"BG$A4V0c$($k$HBgJQ$J$3$H$K$J$C$?$j$9$k$N$GCm0U!#(B

$ bash ./AutoCompile.bash


5. $BBg$-$J%W%m%0%i%`$X$NBP1~!(%i%$%V%i%j2=(B

$B$3$&$7$FJ,3d$7$?(BC$B%=!<%9%U%!%$%k$N$&$A!"A4A3=q$-49$($J$$$G;H$$B3$1$k4X?t72$K$D$$$F$O!"$=$N$&$A!"!V%=!<%9!W$G$O$J$/!"%3%s%Q%$%k:Q$_$N>uBV$GJ]B8$7$F$*$/$[$&$,%3%s%Q%$%k$NJ$1$k$@$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$$$&%i%$%V%i%j$,$G$-$k$H!"$"$H$O$=$l$rMxMQ$7$FMM!9$J%W%m%0%i%`$r=q$$$F$_$k$3$H$,$G$-$^$9!#(B
header$B%U%!%$%k$O!"%+%l%s%H%G%#%l%/%H%j$K$=$l$,$"$k>l9g$O%@%V%k%/%)!<%H$G%U%!%$%kL>$r0O$_$^$9!#(B

$ gcc -Wall -o ic2-week1-Example1 ic2-week1-Example1.c -I. -L. -lMyFunc
$ gcc -Wall -o ic2-week1-Example2 ic2-week1-Example2.c -I. -L. -lMyFunc

-I$B%*%W%7%g%s$O%X%C%@%U%!%$%k$rC5:w$9$Y$-%G%#%l%/%H%j$r!"(B-L$B%*%W%7%g%s$O%i%$%V%i%j$rC5:w$9$Y$-%G%#%l%/%H%j$r$=$l$>$l<($7$^$9!#(B
$B$3$3$G$O$I$A$i$b(B (ic2wk1_MyFuncLib.h $B$H(B libMyFunc.a) $B%+%l%s%H%G%#%l%/%H%j$K$"$k$H2>Dj$7$F$$$^$9!#(B
-lMyFunc$B$r;XDj$9$k$3$H$G!"$B$B$?$@!"$"$H$G30It%i%$%V%i%j$rMxMQ$9$k$3$H$,=P$F$-$^$9$N$G!"35G0$KFk@w$s$G$$$F$b$i$&$?$a$K1i=,$H$7$F$OMQ0U$7$^$7$?!#(B


$B2]Bj(B1. 2011/09/22$B=PBjJ,(B


kameda[at]iit.tsukuba.ac.jp, 2011.