主题:请高手指点:具有内部链接的全局变量的作用域的问题
两个文件:
//s_and_r.c
[b]static unsigned long int next=1;[/b]
int rand1(void)
{
next=next*1103515245+12345;
return(unsigned int)(next/65535)%32768;
}
void srand1(unsigned int seed)
{
next=seed;
}
//r_drive.c
#include<stdio.h>
extern void srand1(unsigned int);
extern int rand1(void);
int main(void)
{
int count;
unsigned seed;
printf("Enter your choice for seed:\n");
while(scanf("%u",&seed)==1)
{
srand1(seed);
for(count=0;count<5;count++)
printf("%hd\n",rand1());
printf("Enter next seed(q to quit):\n");
}
printf("done\n");
}
问题:既然next声明是全局并且是static那么它应该只可以在文件s_and_r.c中有用,那为什么r_drive.c中的main()可以调用它呢?
我对“文件”“模块”没有什么概念,请大牛指点!
//s_and_r.c
[b]static unsigned long int next=1;[/b]
int rand1(void)
{
next=next*1103515245+12345;
return(unsigned int)(next/65535)%32768;
}
void srand1(unsigned int seed)
{
next=seed;
}
//r_drive.c
#include<stdio.h>
extern void srand1(unsigned int);
extern int rand1(void);
int main(void)
{
int count;
unsigned seed;
printf("Enter your choice for seed:\n");
while(scanf("%u",&seed)==1)
{
srand1(seed);
for(count=0;count<5;count++)
printf("%hd\n",rand1());
printf("Enter next seed(q to quit):\n");
}
printf("done\n");
}
问题:既然next声明是全局并且是static那么它应该只可以在文件s_and_r.c中有用,那为什么r_drive.c中的main()可以调用它呢?
我对“文件”“模块”没有什么概念,请大牛指点!