VC6.0环境
文件1.c
#include <stdio.h>
void func_otherSourceFile()
{
printf("this function is written in a file where some functions are located\n");
}
文件2.c
#include <stdio.h>
//在这里声明的函数在整个文件范围内有效,声明一次之后,本文件中所有函数都可以调用被声明的函数
void pub_Moduale();
void func_otherSourceFile();
int main(int argc,char*argv[])
{
int func_withMain(char*);//声明子函数:在这里声明的函数只在主调函数范围内有效!
func_withMain("hi,你好啊!");
pub_Moduale();//在main函数之前已经声明过了,全文件有效。
func_otherSourceFile();//这个函数是定义在另外一个文件里面的
return 0;
}
int func_withMain(char*msg)
{
func_otherSourceFile();
printf("this function is written within the source file where main() is located\n");
printf("传入的数据是:%s\n",msg);
pub_Moduale();//全文件有效函数的一个调用例子。
return 0;
}
void pub_Moduale()
{
func_otherSourceFile();
printf("我是一个公共模块!\n");
}
运行结果:
this function is written in a file where some functions are located
this function is written within the source file where main() is located
传入的数据是:hi,你好啊!
this function is written in a file where some functions are located
我是一个公共模块!
this function is written in a file where some functions are located
我是一个公共模块!
this function is written in a file where some functions are located
Press any key to continue