別モジュールのオブジェクト利用(C言語の場合)
C言語にはスコープを管理するための文法的なルールが無いため、初学者には注意が必要である。
code:scope_c1.c
#include<stdio.h>
#include<math.h>
int main(void){
double x, y;
printf("Hello");
x = M_PI / 2.;
y = sin(x);
printf("Result:%f", y);
return 0;
}
上のプログラムは、
code:scope_c2.c
#include<stdio.h>
#include<math.h>
int main(void){
double x, y;
stdio.printf("Hello");
x = math.M_PI / 2.;
y = math.sin(x);
stdio.printf("Result:%f", y);
return 0;
}
のように
関数 printf はライブラリ stdio
関数 sin と定数値の M_PI はライブラリ math
のスコープに属しているように記述するのが自然である。
その他の要素はPythonにおけるビルトインオブジェクトに相当する。