- 论坛徽章:
- 0
|
在linux下:- #include <stdio.h>
- int a;
- int a = 1;
- int main(void)
- {
- printf("a = %d\n",a);
- }
复制代码 这样都能编译过,为什么呢?
对于这个问题,我还做了一个测试,这个测试的结果让我开始怀疑人生!!- root@ubuntu:/home/hello# ls
- hello.c hello-test.c hello-test.h
- root@ubuntu:/home/hello# cat hello-test.c
- #include <stdio.h>
- volatile int a=1;
- void puta(void)
- {
- printf("a = %d in hello-test\n",a);
- }
- root@ubuntu:/home/hello# cat hello-test.h
- void puta(void);
- root@ubuntu:/home/hello# cat hello.c
- #include <stdio.h>
- #include "hello-test.h"
- int a;
- int main()
- {
- a = 2;
- printf("a = %d\n",a);
- puta();
- return 0; }
- root@ubuntu:/home/hello# gcc hello.c hello-test.c -o hello
- root@ubuntu:/home/hello# ./hello
- a = 2
- a = 2 in hello-test
- root@ubuntu:/home/hello#
复制代码 从结果中可以看出,对hello.c中的a 进行修改实际就是对hello-test.c中的a进行修改。
那么请问int a;是声明吗?难道没有分配内存吗?还是有其它原因?求解ing!!!!!!!!!!!!!!!!!! |
|