假设一个C语言程序有两个源文件:main.c和procl.c,它们的内容如图所示。
a)main.c文件
1 #include <stdio.h>
2 unsigned x=257;
3 short y,z=2;
4 void procl(void);
5 void mian()
6 {
7 procl();
8 printf("x=%u,z=%d\n",x,z);
9 return 0;
10 }
b)procl.c文件
1 double x;
2
3 void procl()
4 {
5 x=-1.5;
6 }
回答下列问题。
(1)在上述两个文件中出现的返回哪些是强符号?哪些是弱符号?
(2)程序执行后打印的结果是什么?请分别画出第7行的procl()函数调用前、后,在地址&x和&z中存放的内容。若第3行改为“short=1,z=2;”打印结果是什么?
(3)修改文件procl,使得main.c能输出正确的结果(即x=7,z=2)。要求修改时不能改变任何变量的数据类型和名字。
// a)main.c文件
#include <stdio.h>
unsigned x=257;
short y,z=2;
void procl(void);
int main() // 题目里字母有问题
{
procl();
printf("x=%u,z=%d\n",x,z);
return 0;
}
// b)procl.c文件
double x;
void procl()
{
x=-1.5;
}
以下是编译之后的提示:
ld: warning: tentative definition of '_x' with size 8 from '/var/folders/kw/ywzc0sr91yl1fgffp6j4s5y00000gn/T/proc-43a858.o' is being replaced by real definition of smaller size 4 from '/var/folders/kw/ywzc0sr91yl1fgffp6j4s5y00000gn/T/main-5f3685.o'
执行结果:x=0,z=0